在Android 5.0 Lollipop中使用ActionMode ActionBar(使用AppCompat)

And*_*kov 38 android android-appcompat android-actionbar material-design android-5.0-lollipop

我用这个教程来改造我的Lollipop Holo应用程序:http: //android-developers.blogspot.ru/2014/10/appcompat-v21-material-design-for-pre.html

是)我有的:

  1. 主题

    <style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
      <item name="windowActionModeOverlay">true</item>
      <item name="colorPrimary">@color/theme_primary</item>
      <item name="colorPrimaryDark">@color/theme_primary_dark</item>
      <item name="colorAccent">@color/theme_accent</item>
    </style>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 工具栏布局

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/toolbar"
      android:layout_height="wrap_content"
      android:layout_width="match_parent"
      android:minHeight="?attr/actionBarSize"
      android:background="?attr/colorPrimary"
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
    Run Code Online (Sandbox Code Playgroud)
  3. 在多选模式下使用ListFragment片段从ActionBarActivity继承的活动

    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

结果:工具栏正常.它使用sepcified主题颜色,但ActionMode中的ListFragment使用的ActionBar(通过点击并保持列表项激活)具有标准的Dark.ActionBar颜色.操作栏的弹出菜单也使用黑暗主题.

我尝试了所有的SO技巧,但仍然无法解决这个问题.我将不胜感激任何帮助.

BTW.我发现ActionBar的深色是由工具栏引起的app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar",但不知道如何解决这个问题,因为正确的工具栏外观需要这个属性.

工具栏颜色正确 黑暗行动吧

And*_*kov 75

只需将这两行添加到主题中:

<item name="actionModeBackground">@color/theme_primary_dark</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
Run Code Online (Sandbox Code Playgroud)

  • 浪费了大量时间试图让它工作,只是意识到,为了让它在AppCompat的工具栏中工作,你将不得不删除项目名称的_"android:"_部分.希望这有助于任何其他人阅读这个线程:) (29认同)