安卓奇巧 : All my app content appears behind the ActionBar and StatusBar after changing StatusBar color

标签 android android-actionbar android-styles android-4.4-kitkat

我已经针对 KitKat 创建了一个单独的 xml 样式文件,并且我已经设法更改了状态栏的颜色。图片上唯一的副作用是,所有内容现在都向上移动到状态栏下方。我的问题是如何在不覆盖状态栏的情况下更改状态栏的颜色,或者我如何知道我需要在我的内容上放置的确切顶部边距,以便它在 ActionBar 之后而不是下方开始。当然,我需要它在所有屏幕尺寸和密度上都按预期运行。谢谢

Navigation drawer and all content appears beneath the ActionBar and Status Bar

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/

相关文章:

Android:在 RecyclerView 中的项目之间添加分隔符

Android - 覆盖 android 布局文件中的样式

android - 如何在android中通过蓝牙向配对设备发送短信?

java - Android - 我应该使用什么从远程数据库获取数据?

android - 不要在 onBackPressed 上调用 onDestroy

android - 更改 Android ActionBar 选项卡文本样式不起作用

android - getActionBar()、getSupportActionBar() 返回 java.nullpointer.exception

android - 如何为 ListView 中的每个 Button 获取多个监听器?

android - 如何隐藏 ActionBar 的图标?

android - 为 Android 中的所有 editTexts 设置一致的主题