[英]Issue Changing SearchView's Back Button Icon Color - Android Studio
I am trying to change the color of the close button and the back button of my SearchView
.我正在尝试更改
SearchView
的关闭按钮和后退按钮的颜色。 I have got the color of the close button changing as expected, but I am having issues getting the back button's color to change.我已经让关闭按钮的颜色按预期改变了,但是我在改变后退按钮的颜色时遇到了问题。 I want them both to be black, but the back button is stuck as white right now.
我希望它们都是黑色的,但后退按钮现在卡在白色。
I have looked through a bunch of solutions to similar answers, but most are making style changes to the app's Toolbar
.我已经查看了一堆类似答案的解决方案,但大多数都在对应用程序的
Toolbar
进行样式更改。 I have created a custom menu
resource and do not have a Toolbar
to change the style of.我创建了一个自定义
menu
资源,但没有可更改其样式的Toolbar
。
I have also tried changing the Drawable
icon of the support action bar using the setHomeAsUpIndicator
function, but this had no effect.我还尝试使用
setHomeAsUpIndicator
function 更改支持操作栏的Drawable
图标,但这没有效果。
This is the small amount of code I am using to change the close and back button colors.这是我用来更改关闭和后退按钮 colors 的少量代码。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem menuItem = menu.findItem(R.id.navbar_search);
SearchView searchView = (SearchView) menuItem.getActionView();
ImageView closeImgView = searchView.findViewById(R.id.search_close_btn);
closeImgView .setColorFilter(Color.BLACK);
ImageView backImgView = searchView.findViewById(R.id.search_mag_icon);
backImgView .setColorFilter(Color.BLACK);
.
.
.
}
Is this back button not the same as the R.id.search_mag_icon
?这个后退按钮与
R.id.search_mag_icon
不一样吗? If not, then where is this back button coming from and how can I change its style?如果不是,那么这个后退按钮是从哪里来的,我该如何改变它的风格?
You can try for setting your imageview colour in xml like this您可以尝试像这样在 xml 中设置您的 imageview 颜色
<ImageView
android:id="@+id/search_mag_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="your image file"
android:backgroundTint="@android:color/black" /*for changing your image colour*/
/>
or try use setBackgroundColour for alternate或者尝试使用 setBackgroundColour 作为替代
search_mag_icon.setBackgroundColor(Color.parseColor("#00000"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.