问题更改搜索视图的后背按钮图标颜色 - Android Studio
我正在尝试更改关闭按钮的颜色和搜索视图
的背面按钮。我的关闭按钮的颜色按预期更改了,但是我遇到的问题要更改后按钮的颜色。我希望它们俩都是黑色的,但是后面按钮现在像白色一样被卡住。
我已经浏览了许多解决方案来为类似的答案,但是大多数正在对应用程序的工具栏进行更改。我创建了一个自定义
菜单
资源,并且没有一个工具栏
可以更改样式。
我还尝试使用可绘制的
使用sethomeAsupIndicator
函数更改支持操作栏的图标,但这没有效果。
这是我使用的少量代码来更改近距离和背面的按钮颜色。
@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);
.
.
.
}
此返回按钮与r.id.search_mag_icon
不一样吗?如果不是,那么这个后退按钮来自哪里,我该如何更改其样式?
I am trying to change the color of the close button and the back button of my 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
. I have created a custom menu
resource and do not have a Toolbar
to change the style of.
I have also tried changing the Drawable
icon of the support action bar using the setHomeAsUpIndicator
function, but this had no effect.
This is the small amount of code I am using to change the close and back button 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
? If not, then where is this back button coming from and how can I change its style?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试以这样的XML设置imageView颜色
,也可以尝试使用SetbackgroundColour进行替代
You can try for setting your imageview colour in xml like this
or try use setBackgroundColour for alternate