对于我的 Android 应用程序,我希望我的应用程序在 KitKat(API 级别 19)上具有半透明状态和导航栏。如何使 19 级 API 操作系统具有透明状态/导航栏,而非 KitKat 操作系统具有普通栏。
最佳答案
您需要定义自定义主题,并为 API 级别 19 设置这些属性。
首先,在 res\values
中创建一个 styles.xml
文件
它应该包含以下内容:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyCustomTheme" parent="@android:style/Theme">
</style>
</resources>
根据您想要的基本主题,parent="@android:style/Theme"
可能会有所不同(例如 Theme.Light
、Theme.Holo
、Theme.Holo.Light
或其他)。
然后在 res\values-v19
中创建一个类似的 styles.xml
文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyCustomTheme" parent="@android:style/Theme.Holo">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
(与之前相同,父级可能不同)。
在您的 AndroidManifest.xml
文件中,查找 application
节点,然后添加/更新主题属性,即
<application
android:icon= ...
android:theme="@style/MyCustomTheme">
关于java - (Android) API 特定样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24191068/