工具栏ActionMode似乎在Lollipop之前的设备上忽略了我的风格。
这是我的风格:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:textColorPrimary">#DD000000</item>
<item name="android:textColorSecondary">#8A000000</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<!-- Set AppCompat’s color theming attrs -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/secondary</item>
<item name="colorAccent">@color/accent</item>
<item name="android:actionModeStyle">@style/Widget.ActionMode</item>
<item name="android:actionModeBackground">@drawable/toolbar_action_background</item>
<item name="android:actionModeCloseDrawable">@drawable/ic_arrow_back_white_24dp</item>
</style>
<style name="Widget.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
<item name="android:background">@drawable/toolbar_action_background</item>
<item name="android:titleTextStyle">@style/TitleTextStyle</item>
</style>
<style name="TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#fff</item>
</style>
我的工具栏xml
<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:elevation="4dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary" />
我检查过这些问题: How to specify dark action mode with my theme Toolbar and Contextual ActionBar with AppCompat-v7 Unable to style action mode when using Toolbar
预期的行为,在棒棒糖上运作良好:
如何看待kitkat:
答案 0 :(得分:10)
通过在我的主题中指定android命名空间来解决:
...
<item name="actionModeStyle">@style/ActionMode</item>
<item name="android:actionModeStyle">@style/ActionMode</item>
...
<style name="ActionMode" parent="Widget.AppCompat.ActionMode">
<item name="android:background">@drawable/toolbar_action_background</item>
<item name="background">@drawable/toolbar_action_background</item>
</style>
答案 1 :(得分:0)
查看您的Toolbar
主题:
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
第一个style
,你没有给出一个名字。你错过了一些台词。然后,让我们假设style
没有name
,name
是ToolbarStyle
,其<item name="colorPrimary">@color/primary</item>
行确实很重要。然后在Toolbar
布局中,将app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
替换为app:theme="@style/ToolbarStyle"
。然后<item name="colorPrimary">@color/primary</item>
会为您的Toolbar
背景添加颜色。我们现在清楚了吗?