SearchView 风格干扰 Toolbar Style Actionbar
SearchView style disturbs Toolbar Style Actionbar
我需要什么:我需要带有 白色文本 的操作栏,就像这样:
SearchView 最近查询建议 像这样定制:
问题:我可以同时做,但我不能同时做,当我将标题设置为白色时,建议样式消失了。我会展示我是如何处理这个的。
布局建议
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 中更改操作栏的样式(查找了数千个问题)但无法达到预期的结果。
我创建了一个 Dark ActionBar Style,所以它的按钮、标题、副标题都是白色的(如我所愿)。然后我将此样式设置为我的操作栏。
然后,我在 CustomActionBar 样式中设置 SearchView 样式。
警告:如果我将 searchViewStyle 设置在 CustomActionBar 之外,它将不起作用,它必须在 CustomActionBar 样式内才能起作用。
<style name="CustomActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="searchViewStyle">@style/MySearchViewStyle</item>
</style>
<android.support.design.widget.AppBarLayout
android:theme="@style/CustomActionBar">
<android.support.v7.widget.Toolbar
.../>
<android.support.design.widget.TabLayout
.../>
</android.support.design.widget.AppBarLayout>
我需要什么:我需要带有 白色文本 的操作栏,就像这样:
SearchView 最近查询建议 像这样定制:
问题:我可以同时做,但我不能同时做,当我将标题设置为白色时,建议样式消失了。我会展示我是如何处理这个的。
布局建议
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 中更改操作栏的样式(查找了数千个问题)但无法达到预期的结果。
我创建了一个 Dark ActionBar Style,所以它的按钮、标题、副标题都是白色的(如我所愿)。然后我将此样式设置为我的操作栏。
然后,我在 CustomActionBar 样式中设置 SearchView 样式。
警告:如果我将 searchViewStyle 设置在 CustomActionBar 之外,它将不起作用,它必须在 CustomActionBar 样式内才能起作用。
<style name="CustomActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="searchViewStyle">@style/MySearchViewStyle</item>
</style>
<android.support.design.widget.AppBarLayout
android:theme="@style/CustomActionBar">
<android.support.v7.widget.Toolbar
.../>
<android.support.design.widget.TabLayout
.../>
</android.support.design.widget.AppBarLayout>