我假设backgroundSplit
属性控制CAB
底部显示的橙色线:
当我去设置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>
如果我将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
也无关紧要。