【发布时间】:2018-07-05 13:05:25
【问题描述】:
我需要什么:我需要带有 白色文本的操作栏,例如:
SearchView 最近的查询 Suggestions 自定义如下:
问题:我可以同时做这两个,但我不能同时做,当我将标题设置为白色时,建议样式消失。我将展示我是如何处理这个问题的。
建议布局
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="searchViewStyle">@style/MySearchViewStyle</item>
</style>
<style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView" >
<item name="suggestionRowLayout">@layout/item_suggestions</item>
</style>
@layout/item_suggestions:这是我自定义建议项目布局的地方,它WORKS完美。
操作栏样式
因为我的 AppTheme 是 Light,所以我的操作栏和按钮的默认标题是黑色的。要覆盖(白色标题和图标),我执行以下操作:
<android.support.design.widget.AppBarLayout
...>
<android.support.v7.widget.Toolbar
...
android:theme="@style/ThemeOverlay.MyApp.ActionBar"/>
styles.xml
<style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/colorWhite</item>
</style>
最终问题:当我将此主题应用于操作栏以获取白色文本和图标时。 BOWN,SearchView 建议的主题不再起作用。同时实现两者的聪明方法是什么?
我已经尝试过什么
我已经尝试在styles.xml中更改操作栏的样式(查找了数千个问题)但无法达到预期的结果。
【问题讨论】:
标签: android android-layout android-actionbar android-styles