简体   繁体   English

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

[英]Styling ActionMode ActionBar in Android 5.0 Lollipop (with AppCompat)

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

What I have: 是)我有的:

  1. Theme 主题

     <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> 
  2. Toolbar layout 工具栏布局

     <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" /> 
  3. Activity inherited from ActionBarActivity with a ListFragment fragment in the multi-choice mode 在多选模式下使用ListFragment片段从ActionBarActivity继承的活动

    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

Result : The toolbar is OK. 结果 :工具栏正常。 It uses the sepcified theme colors, but the ActionBar used by the ListFragment in the ActionMode (activated by tap-and-hold a list item) has the standard Dark.ActionBar colors. 它使用sepcified主题颜色,但ActionMode中的ListFragment使用的ActionBar(通过点击并保持列表项激活)具有标准的Dark.ActionBar颜色。 Also the popup menu of the action bar uses the dark theme. 操作栏的弹出菜单也使用黑暗主题。

I tried all the SO tricks, but still cannot solve that. 我尝试了所有的SO技巧,但仍然无法解决这个问题。 I will appreciate any help. 我将不胜感激任何帮助。

BTW. BTW。 I found that the dark colors of the ActionBar are caused by the toolbar's app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" , but have no idea how solve this, because this attribute is needed for the correct toolbar appearance. 我发现ActionBar的深色是由工具栏的app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" ,但不知道如何解决这个问题,因为正确的工具栏外观需要这个属性。

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

Just add these two lines to the theme: 只需将这两行添加到主题中:

<item name="actionModeBackground">@color/theme_primary_dark</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>

This might also be helpful in addition to @Andrey Shcherbakov 's answer if you want to have more control of each individual color. 除了@Andrey Shcherbakov的答案之外,如果您想要更好地控制每种颜色,这也可能会有所帮助。

<!-- action bar title text color, icon color (ie: back icon, icons when editing text)-->
<item name="android:textColorPrimary">#FFFF00</item>

<!-- action bar background color-->
<item name="android:colorBackground">#444400</item>

<!-- color of line under contextual action bar-->
<item name="colorControlActivated">#00CC00</item>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM