我想将状态栏背景设置为渐变主题,状态栏和动作栏颜色应该是相同的渐变可绘制,根据文档,我们可以使用API级别21及以上的状态栏将颜色设置为使用
<item name="android:statusBarColor">@color/colorPrimary</item>
Run Code Online (Sandbox Code Playgroud)
但我正在寻找类似的东西
<item name="android:statusBarDrawable">@drawable/myDrawable</item>
Run Code Online (Sandbox Code Playgroud)
我见过使用的例子
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
Run Code Online (Sandbox Code Playgroud)
但在那种情况下状态栏和操作栏重叠(使用fitSystemWindow = true但仍未解决)也尝试使用https://github.com/jgilfelt/SystemBarTint这个库,但仍然没有运气
先感谢您!!
我正在使用Action Bar Compat,因此带导航抽屉的操作栏向下兼容到API级别9,我想更改操作栏的背景.
我复制了Android开发者的代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">@drawable/actionbar_background</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
这就是问题所在.
当我将图像绘制或颜色作为背景时,它工作正常.但是我想将背景定义为渐变形状,所以我actionbar_background看起来像:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<gradient
android:startColor="@color/ac_bg_start"
android:endColor="@color/ac_bg_end"
android:type="linear"/>
<size
android:width="1dp"
android:height="48dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
我希望它以水平方式重复,但即使这样也会导致错误,实际上是非常有趣的错误.当我尝试运行应用程序时,测试设备甚至模拟器都会重新启动.DeadObjectException在重新启动之前我能够捕获.
背景画如何看起来像?