[英]How can I use Light SearchView on Dark App Bar on android?
This is my main activity xml: 这是我的主要活动xml:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_search" />
This is my styles.xml 这是我的styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
The problem is that I want to use white text on the AppBar, but at the same time I want the search suggestions to have dark text on white background (like holo). 问题是我想在AppBar上使用白色文本,但同时我希望搜索建议在白色背景上具有深色文本(如全息)。 Currently the suggestions are shown in dark theme.
目前,建议以深色主题显示。 If I use ThemeOverlay.AppCompat.ActionBar, then the suggestions turn white but the text on appbar is turned Black, and I want it to remain white.
如果我使用ThemeOverlay.AppCompat.ActionBar,则建议将变为白色,但appbar上的文本将变为黑色,并且我希望它保持白色。
Please help me! 请帮我! I am also attaching screenshots for demonstration purposes:
我还附有屏幕截图以进行演示:
Here is how I succeeded to achieve that: 这是我成功实现的方式:
You need to override the styles autoCompleteTextViewStyle
and textAppearanceSearchResultTitle
in your theme: 您需要在主题中覆盖样式
autoCompleteTextViewStyle
和textAppearanceSearchResultTitle
:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="autoCompleteTextViewStyle">@style/myAutoCompleteTextViewStyle</item>
<item name="textAppearanceSearchResultTitle">@style/mySearchResult</item>
...
</style>
<style name="myAutoCompleteTextViewStyle" parent="Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:popupBackground">@color/White</item>
</style>
<style name="mySearchResult" parent="TextAppearance.AppCompat.SearchResult.Title">
<item name="android:textColor">@color/Black</item>
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.