方式一:代码设置
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){//判断系统版本5.0以上 Window window = this.getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // window.setStatusBarColor(0xff01c7d4); //顶部状态栏设置根布局的背景色 也可以设置某个view的背景色 window.setStatusBarColor(activity_offline_help.getDrawingCacheBackgroundColor()); //底部导航栏设置根布局的背景色 也可以设置某个view的背景色 window.setNavigationBarColor(activity_offline_help.getDrawingCacheBackgroundColor()); }方式二:style适配
1.创建一个values-v21文件夹
2.写入theme
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="android:windowTranslucentStatus">false</item> <!--<item name="android:windowTranslucentNavigation">true</item>-->!<!--底部导航条 透明--> <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色--> <item name="android:statusBarColor">@color/app_title</item> <item name="android:fitsSystemWindows">true</item><!--导致dialog 边框内陷--> </style>3.在manifest中应用
<activity android:name=".activity.StorageSetActivity" android:screenOrientation="portrait" android:theme="@style/AppBaseTheme" />
android 沉浸式主题记录
最新推荐文章于 2022-10-04 23:46:16 发布
本文详细介绍了两种实现Android沉浸式主题的方法:一是通过代码直接设置,二是利用style进行适配,包括在values-v21文件夹中创建theme以及在AndroidManifest.xml中应用该theme。
摘要由CSDN通过智能技术生成