如何在actionBarStyle中使用searchView?

时间:2017-06-20 14:28:13

标签: android android-layout

我的应用程序样式层次结构如下:

<style name="MiddleBaseApTheme" parent="@style/BaseAppTheme">
        <item name="android:actionBarStyle" tools:targetApi="11">@style/MainActionBarStyle</item>

<item name="navigationIcon">@drawable/ic_arrow_back_black56</item>

        <item name="actionBarStyle">@style/MainActionBarStyle</item>
</style>

然后,我将动作栏样式定义为:

<style name="MainActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
    <item name="android:elevation" tools:targetApi="21">@dimen/action_bar_elevation</item>
    <item name="elevation">@dimen/action_bar_elevation</item>
    <item name="popupTheme">@style/CustomPopup</item>

    <item name="android:background">@android:color/holo_red_light</item>

    <!-- Support library compatibility -->
    <item name="background">@android:color/holo_red_light</item>

</style>

这已成功将app栏显示为:

enter image description here

现在我想更进一步尝试:

  1. 要使用相同的样式并在现有操作栏上添加搜索栏,我尝试使用:
  2. <item name="searchViewStyle">@style/AppTheme.SearchView</item>

    在MiddleBaseTheme上,AppTheme.SearchView包含AutoCompleteBox TextView样式:

    <style name="AppTheme.SearchView" parent="Widget.AppCompat.Light.SearchView">
        <item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextView</item>
    </style>
    

    但这并没有在Action栏上显示任何SearchView ......为什么?

1 个答案:

答案 0 :(得分:0)