1.修改状态栏颜色,即修改application主题theme 或者 activity主题theme
values/styles/
<!--状态栏颜色 样式 -->
<style name="TranslucentTheme" parent="AppTheme"> </style>
values-v19/styles
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> //设置为true,意味着xml布局延伸到状态栏 <item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item> <item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">false</item> </style>
values-v21/styles
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> //设置为false,意味着布局不会延伸到状态栏 <item name="android:windowTranslucentStatus" tools:targetApi="kitkat">false</item> <item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">false</item> <!--Android 5.x开始需要把颜色设置为程序的主题色白色,否则导航栏会呈现系统默认的浅灰色--> <item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/white</item> </style>
2.在application主题theme 或者 activity主题theme设置
android:theme="@style/TranslucentTheme"
3.设置状态栏字体图标颜色
在activity的onCreate()中setContentView之前设置
//状态栏中的文字颜色和图标颜色,需要android系统6.0以上,而且目前只有一种可以修改(一种是深色,一种是浅色即白色) if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { //修改为深色,因为我们把状态栏的背景色修改为主题色白色,默认的文字及图标颜色为白色,导致看不到了。 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); }
扫描二维码关注公众号,回复:
5732320 查看本文章