java - android studio开发,toolbar上的searchview图标如何更改?
天蓬老师
天蓬老师 2017-04-17 15:33:26
[Java讨论组]

默认的icon是黑色的,如何更改为白色?
在toolbar的menu里改icon文件没有效果

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(2)
黄舟

更改图像编码onPrepareOptionsMenu在这段我建议创建一个方法,通过菜单项从onprepareoptionsmenu在那方法做的任务。

PHP中文网

Update

搬运工
How to change SearchView default icon?
Changing the background drawable of the searchview widget

Unfortunately, there is no easy way to change the SearchView icon to a custom drawable, since the theme attribute searchViewSearchIcon is not public. See this answer for details.

However, I think that your problem is caused by inheriting from the wrong theme. Please use > android:Theme.Holo.Light.DarkActionBar as the base for your theme. Then the default icons on > the action bar should have a light color.

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    ...
</style>

我的测试结果:
values-v14/styles.xml中设置style为android:Theme.Holo.Light,对应图片的上部分;
设置style为android:Theme.Holo.Light.DarkActionBar,对应图片的下部分;

Old Answer: 这段代码确实改不了SearchView icon,只能改普通的 menu item

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_full_player, menu);
        
        MenuItem item = menu.findItem(R.id.catcher_action_playPause);
        Drawable icon = getResources().getDrawable(R.drawable.ic_pause_circle_outline_white_36dp);
        item.setIcon(icon);
        
        return super.onCreateOptionsMenu(menu);
    }
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号