我想创建一个活动与不在ActionBar中的SearchView(实际上,我使用NoActionBar主题)。现在,我想这个搜索查看有圆角(不是的EditText实际搜索查看里面,但搜索查看本身),android自定义searchView圆角
这样的:Mockup
所有我可以管理是这样的:actual SearchView。
有人能告诉我我必须改变什么吗? XML活动的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="@color/theBlue">
<SearchView
android:id="@+id/search_view"
android:layout_width="1000dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="@drawable/bg_white_rounded"
android:clickable="true"/>
</RelativeLayout>
可绘制/ bg_white_rounded.xml的代码:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff"/>
<corners android:radius="10dp"/>
<padding android:left="0dp"
android:bottom="0dp"
android:right="0dp"
android:top="0dp"/>
</shape>
活性的代码:
public class MainActivity extends AppCompatActivity {
SearchView searchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get search view and modify it to our needs
searchView = (SearchView) findViewById(R.id.search_view);
searchView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchView.onActionViewExpanded();
}
});
//int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
//int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_badge", null, null);
View searchPlate = searchView.findViewById(searchPlateId);
//View searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchPlate.setBackgroundResource(R.drawable.bg_white_rounded);
}
}
注释行事我已经尝试过但没有工作。 谢谢!