android 开发中状态栏的颜色、样式等修改教程!第一种是设置特定颜色的状态栏,不是渐变透明的在清单文件里面的apilication使用。
<application android:name=".TntApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/colorPrimaryDarkitem> <item name="colorPrimaryDark">@color/colorPrimaryDarkitem> <item name="colorAccent">@color/colorAccentitem> <item name="actionMenuTextColor">@color/colorFFFFFFitem> <item name="android:windowTranslucentNavigation" tools:ignore="NewApi">falseitem>
style>
1.colorPrimary 应用的主要色调,actionBar默认使用该颜色,Toolbar导航栏的底色
2.colorPrimaryDark 应用的主要暗色调,statusBarColor默认使用该颜色
3.colorAccent 为EditText,CheckBox,RadioButton,SwitchCompat等一般控件的选中效果默认采用该颜色,比如光标
4.actionMenuTextColor 菜单栏组件的字体颜色
第二种,设置渐变透明的状态栏,底部有虚拟按钮时会自动顶起,
getWindow().requestFeature(Window.FEATURE_NO_TITLE); Window window = getWindow(); //4.4版本及以上 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // Translucent navigation bar window.setFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } //5.0版本及以上 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.TRANSPARENT);
放在baseActivity就可以了