我为Activity
设置了以下布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_charts_activity"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- App bar -->
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- Toolbar -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/App.Theme.Overlay"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<!-- Tab layout -->
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@color/white_80" />
</android.support.design.widget.AppBarLayout>
<!-- View pager -->
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
使用 App.Theme.Overlay :
<style name="App.Theme.Overlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlActivated">@android:color/white</item>
<item name="searchViewStyle">@style/App.Theme.SearchView</item>
</style>
和 App.Theme.SearchView :
<style name="App.Theme.SearchView" parent="Widget.AppCompat.Light.SearchView">
<item name="searchHintIcon">@null</item>
<item name="queryBackground">?attr/colorPrimary</item>
<item name="submitBackground">?attr/colorPrimary</item>
</style>
Activity
的菜单操作包含SearchView
:
<?xml version="1.0" encoding="utf-8"?>
<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="@mipmap/search"
android:title="@string/search_a_product"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="collapseActionView|ifRoom" />
</menu>
当我点击搜索图标并输入一些文字时,我认为它具有相同的背景颜色,因为我看不到它,但是我的搜索结果却是如此。如果SearchView
不在应用栏内(但我需要它),则不会发生这种情况。你能提供一些帮助吗?非常感谢。