我已经在菜单文件夹中添加了搜索图标,并为此创建了menu.xml文件。在这里,我从Android Image Asset创建了浅绿色的自定义搜索图标。
当我在drawable中添加这个浅绿色的搜索图标并运行项目时,它是白色的。搜索提示和搜索文本也是白色的。因为我有白色的操作栏,所有的搜索图标都是不可见的。请帮助纠正此问题。
我已经为搜索图标创建了一个menu.xml文件,并在可绘制的文件夹中添加了浅绿色的搜索图标。我使用的是Theme.AppCompat.Light.DarkActionBar和我的操作栏颜色,它将它设置为白色。
Styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="titleTextColor">@color/titleColor</item>
<item name="colorControlNormal">@color/colorAccent</item>menu.xml文件:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView"
android:title="@string/search_string" />
<!--<item
android:id="@+id/action_settings"
android:title="Settings"/>-->
</menu>活动代码:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
MenuItem item = menu.findItem(R.id.action_search);
//additonal code
return super.onCreateOptionsMenu(menu);我希望自定义颜色搜索图标只显示在白色的行动栏,而不是白色的搜索图标(现在显示)。以及黑色的搜索查询搜索提示。请帮帮我。
发布于 2019-04-18 21:22:58
最好的选择是对菜单中的项目使用自定义布局。
此外,您还可以尝试遵循此article
发布于 2019-04-18 21:28:52
您需要使用android.support.v7.widget.SearchView:
<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
<!-- Gets rid of the search icon -->
<item name="searchIcon">@drawable/ic_search</item>
<!-- Gets rid of the "underline" in the text -->
<item name="queryBackground">@color/white</item>
<!-- Gets rid of the search icon when the SearchView is expanded -->
<item name="searchHintIcon">@null</item>
<!-- The hint text that appears when the user has not typed anything -->
<item name="queryHint">@string/search_hint</item>
</style>发布于 2021-07-29 12:04:15
对我来说起作用的是设置前景。这会改变搜索视图的图标颜色。
<style name="MySearchViewTheme" parent="Widget.AppCompat.SearchView">
<item name="android:background">@color/grey_dark</item>
<!-- Changes icons color -->
<item name="android:colorForeground">@color/grey_400</item>
</style>https://stackoverflow.com/questions/55746903
复制相似问题