1.android 改变状态栏的颜色,2 设置透明渐变式的样式!,设置状态栏为透明的渐变的

来源:互联网 发布:贵州大数据战略 编辑:程序博客网 时间:2024/04/30 03:12
第一种是设置特定颜色的状态栏,不是渐变透明的在清单文件里面的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">    <!-- Customize your theme here. -->    <item name="colorPrimary">@color/colorPrimaryDark</item>    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>    <item name="colorAccent">@color/colorAccent</item>    <item name="actionMenuTextColor">@color/colorFFFFFF</item>    <item name="android:windowTranslucentNavigation" tools:ignore="NewApi">false</item>

</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就可以了



原创粉丝点击