我正在尝试更改位于Android操作栏searchview小部件中的drawable.
目前它看起来像这样:

但我需要将蓝色背景改为红色.
我尝试过很多东西,不用滚动我自己的搜索小部件,但似乎没有任何工作.
有人能指出我改变这个方向的正确方向吗?
android styles android-actionbar searchview background-drawable
我在我的项目中使用工具栏搜索小部件.一切正常,但期待我完全坚持删除工具栏中搜索字段下方的下划线.我尝试过很多解决方案但没有任何效果.以下是我尝试过的一些解决方案.
要求是删除图像中的白色下划线

Ist解决方案:
//Removing underline
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
View searchPlate = searchView.findViewById(searchPlateId);
if (searchPlate!=null) {
searchPlate.setBackgroundColor (Color.TRANSPARENT);
int searchTextId = searchPlate.getContext ().getResources ().getIdentifier ("android:id/search_src_text", null, null);
}
Run Code Online (Sandbox Code Playgroud)
第二解决方案:
EditText searchEdit = ((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text));
searchEdit.setBackgroundColor(Color.TRANSPARENT);
Run Code Online (Sandbox Code Playgroud)
上面的代码用于更改EditText的背景,但仍然下划线显示在SearchBar中的关闭图标下方.
我用于SearchBar小部件的完整代码如下:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater infl) {
super.onCreateOptionsMenu(menu, infl);
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.action_search, menu);
final SearchView searchView = (SearchView) MenuItemCompat
.getActionView(menu.findItem(R.id.search));
SearchManager searchManager = (SearchManager) getActivity ().getSystemService (getActivity ().SEARCH_SERVICE);
searchView.setSearchableInfo (searchManager.getSearchableInfo (getActivity ().getComponentName ()));
//changing edittext color
EditText searchEdit = …Run Code Online (Sandbox Code Playgroud) 我一直在尝试将自定义字体设置为android.support.v7.widget.SearchView查询提示和View.I中输入的文本.我尝试通过创建TypeFace对象动态地将字体从assests设置为searchView,但问题是"SearchView不包含一个setTypeface(Typeface tf)方法." 我确实尝试过自定义的SearchView类但找不到.
private void setFont(String font1, String font2, String font3)
{
Typeface tf = null;
tf = UiUtil.changeFont(MainActivity.this, font1);
btn1.setTypeface(tf);
tf = UiUtil.changeFont(MainActivity.this, font2);
btn2.setTypeface(tf);
tf = UiUtil.changeFont(MainActivity.this, font3);
btn3.setTypeface(tf);
tf = UiUtil.changeFont(MainActivity.this, font3);
// no set typeface method..
}
Run Code Online (Sandbox Code Playgroud)