当我发布我的笔记本应用程序Android 4.0 - 4.3时,我使用自定义操作栏颜色和自定义操作栏图标(而不是使用标准的浅色和深色操作栏)。我想在Android 4.4上做到这一点,状态栏也将采用我在Action Bar中使用的自定义颜色(即#FFD060)。有没有办法轻松更改我当前的styles.xml以允许4.4利用这个?
我的values-v19文件夹下的styles.xml如下:
<resources>
<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#ffd060</item>
<item name="android:textColor">#fff</item>
<item name="android:icon">@drawable/action</item>
<item name="android:titleTextStyle">@style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:icon">@drawable/action</item>
<item name="android:textColor">#ffffff</item>
</style>
</resources>
我试图实施:
<item name="android:windowTranslucentStatus">true</item>
它会导致我的应用程序的内容向上移动,从状态栏区域开始并被操作栏覆盖。
答案 0 :(得分:15)
更新:在Matt Gaunt(谷歌员工)上发现了一篇关于为Android应用添加半透明主题的精彩文章。这是非常彻底的,并解决了许多人在实现这种风格时似乎遇到的一些问题:Translucent Theme in Android
只需将以下内容添加到自定义样式即可。这可以防止ActionBar后面的内容移动到窗口的顶部,但不能确定屏幕的底部。
<item name="android:fitsSystemWindows">true</item>
答案 1 :(得分:2)
看起来您需要做的就是将此元素添加到您想要半透明状态栏的主题中:
<item name="android:windowTranslucentStatus">true</item>
答案 2 :(得分:2)
在主题
中添加这些行<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:fitsSystemWindows">true</item>
</style>
答案 3 :(得分:0)
您非常接近,只需要更新视图背景颜色:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffd060" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
<!-- your stuff here -->
</LinearLayout>
</FrameLayout>
在AppBaseTheme中指定全局背景颜色也会起作用,但可能会造成混乱,因为它最终会成为所有内容的默认背景颜色。
答案 4 :(得分:0)
将状态栏的颜色更改为windowBackground
<item name="android:windowBackground">@color/window_bg</item>
将半透明效果添加到状态和导航栏
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>