如何更改 SearchView 下方底线的颜色
How to change the color of the bottom line underneath a SearchView
非常简单,如何更改 Android 中 SearchView 底部的线条颜色?我试过 queryBackground、background 和各种其他东西,但似乎无法在 XML 中获取它。我很乐意以编程方式或在 XML 中执行此操作。只是想让它工作!
干杯
你好试试这个可能对你有帮助
android.support.v7.widget.SearchView searchView=findViewById(R.id.search_view);
View v = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
v.setBackgroundColor(Color.parseColor("color code"));
使用 Below 方法改变 SearchView 底线的颜色。
这里我添加蓝色作为底线
private void customizeSearchView() {
int searchTextId = getResources().getIdentifier("android:id/search_src_text", null, null);
EditText searchBox = ((EditText) searchView.findViewById(searchTextId));
searchBox.setBackgroundColor(Color.WHITE);
searchBox.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
int search_plateId = getResources().getIdentifier("android:id/search_plate", null, null);
View mSearchPlate = ((View) searchView.findViewById(search_plateId));
mSearchPlate.setBackgroundColor(Color.BLUE);
int searchCloseImageId = getResources().getIdentifier("android:id/search_close_btn", null, null);
ImageView searchClose = ((ImageView) searchView.findViewById(searchCloseImageId));// change color
searchClose.setBackgroundColor(Color.WHITE);
}
androidx.appcompat.widget.SearchView searchView = findViewById(R.id.Search_Categorie);
View v = searchView.findViewById(androidx.appcompat.R.id.search_plate);
v.setBackgroundColor(Color.parseColor("#ffffff"));
非常简单,如何更改 Android 中 SearchView 底部的线条颜色?我试过 queryBackground、background 和各种其他东西,但似乎无法在 XML 中获取它。我很乐意以编程方式或在 XML 中执行此操作。只是想让它工作!
干杯
你好试试这个可能对你有帮助
android.support.v7.widget.SearchView searchView=findViewById(R.id.search_view);
View v = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
v.setBackgroundColor(Color.parseColor("color code"));
使用 Below 方法改变 SearchView 底线的颜色。
这里我添加蓝色作为底线
private void customizeSearchView() {
int searchTextId = getResources().getIdentifier("android:id/search_src_text", null, null);
EditText searchBox = ((EditText) searchView.findViewById(searchTextId));
searchBox.setBackgroundColor(Color.WHITE);
searchBox.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
int search_plateId = getResources().getIdentifier("android:id/search_plate", null, null);
View mSearchPlate = ((View) searchView.findViewById(search_plateId));
mSearchPlate.setBackgroundColor(Color.BLUE);
int searchCloseImageId = getResources().getIdentifier("android:id/search_close_btn", null, null);
ImageView searchClose = ((ImageView) searchView.findViewById(searchCloseImageId));// change color
searchClose.setBackgroundColor(Color.WHITE);
}
androidx.appcompat.widget.SearchView searchView = findViewById(R.id.Search_Categorie);
View v = searchView.findViewById(androidx.appcompat.R.id.search_plate);
v.setBackgroundColor(Color.parseColor("#ffffff"));