我已经针对 KitKat 创建了一个单独的 xml 样式文件,并且我已经设法更改了状态栏的颜色。图片上唯一的副作用是,所有内容现在都向上移动到状态栏下方。我的问题是如何在不覆盖状态栏的情况下更改状态栏的颜色,或者我如何知道我需要在我的内容上放置的确切顶部边距,以便它在 ActionBar 之后而不是下方开始。当然,我需要它在所有屏幕尺寸和密度上都按预期运行。谢谢
values-v19/styles.xml
<style name="ThemeSelector" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
最佳答案
您应该将以下内容添加到 View 的顶部
android:paddingTop="?android:attr/actionBarSize"
如果您正在使用操作栏的支持库,则需要删除 android: 前缀
android:paddingTop="?attr/actionBarSize"
通过启用半透明系统栏,您的布局将填充系统栏后面的区域,因此您还必须为不应被系统栏覆盖的布局部分启用fitsSystemWindows。
关于安卓奇巧 : All my app content appears behind the ActionBar and StatusBar after changing StatusBar color,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20783945/