Android上下文操作栏(CAB)backgroundSplit属性无效

时间:2016-06-16 14:01:57

标签: android android-styles contextual-action-bar

我假设backgroundSplit属性控制CAB底部显示的橙色线:

with backgroundSplit

当我去设置CAB的样式并更改background颜色时,backgroundSplit会消失。

styles.xml

 <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="actionModeBackground">@drawable/cab_background</item> <!-- Here -->
</style>

cab_background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/colorSecondary"/>
</shape>

without split

如果我将actionModeBackground设置为@color资源而非@drawable,则会发生同样的事情。

......当我这样做时:

styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="actionModeStyle">@style/ActionModeStyle</item> <!-- Here -->
</style>

<style name="ActionModeStyle" parent="Widget.AppCompat.ActionMode">
    <item name="background">@drawable/cab_background</item>
</style>

我在AppCompat源代码中使用的那个之后模拟了我的drawable:

<item name="actionModeBackground">@drawable/abc_cab_background_top_material</item>

abc_cab_background_top_material.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- This is a dummy drawable so that we can refer to the drawable ID -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/white"/>
</shape>

但是,正如评论所指出的那样,这只是一个虚拟的绘画,我似乎无法找到实际使用的那个。我开始认为backgroundSplit实际上没有引用第一张图片中显示的橙色线,并且彩色线条直接写入可绘制文件,因为源代码backgroundSplit设置为@color/colorPrimaryDark,而不是显示的橙色。如果是这样,那个可绘制文件怎么样?

另一方面,如果backgroundSplit实际上是要操纵的属性,这是AppCompat中的错误还是我只是错误地使用它?

我无能为力:

styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="actionModeSplitBackground">@color/colorAccent</item> <!-- Here -->
</style>

......而且这两者都没有:

styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="actionModeStyle">@style/ActionModeStyle</item> <!-- Here -->
</style>

<style name="ActionModeStyle" parent="Widget.AppCompat.ActionMode">
    <item name="background">@drawable/cab_background</item>
    <item name="backgroundSplit">@color/colorAccent</item>
</style>

如果我将backgroundSplit设置为@drawable也无关紧要。

0 个答案:

没有答案
相关问题