android沉浸式状态栏实现细节
来源:互联网 发布:先锋软件职业学院图片 编辑:程序博客网 时间:2024/06/05 14:57
studio,中引入沉浸式兼容库
compile ‘com.readystatesoftware.systembartint:systembartint:1.0.3’
eclipse,可以导入相应的那个类。
第一类,兼容actionbar
第一步:设置activity主题android:theme=”@style/ActionBarTheme”
<style name="ActionBarTheme" parent="android:Theme.Holo.Light.DarkActionBar"><!-- API 14 theme customizations can go here. --><item name="android:actionBarStyle">@style/ActionBarStyle</item></style><style name="ActionBarStyle" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse"><item name="android:background">@color/actionbar_bg</item></style>
第二步:设置状态栏透明,然后设置状态栏沉浸的颜色
@TargetApi(19)private void setTranslucentStatus(boolean on) {Window win = getWindow();WindowManager.LayoutParams winParams = win.getAttributes();final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); }
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); }SystemBarTintManager tintManager = new SystemBarTintManager(this);tintManager.setStatusBarTintEnabled(true);//设置沉浸的颜色 tintManager.setStatusBarTintResource(R.color.statusbar_bg);}
第三步:设置适应windows,在布局文件设置
android:fitsSystemWindows=”true”
如果不设置,应用的ui会顶上去,顶进system ui
ok
第二类 没有actionbar的activity
第一步,设置主题,android:theme=”@style/FullBleedTheme”
<style name="FullBleedTheme" parent="android:Theme.Holo.Light.NoActionBar"><!-- API 14 theme customizations can go here. --></style>
<style name="FullBleedTheme" parent="android:Theme.Holo.Light.NoActionBar.TranslucentDecor"><!-- API 19 theme customizations can go here. --></style>
或者
用toolbar只能设置Theme.AppCompat.NoActionBar主题
<style name="AppThemeToolbar" parent="Theme.AppCompat.NoActionBar"> <item name="colorPrimary">#2196F3</item> <item name="colorPrimaryDark">#2196F3</item> <!--<item name="colorPrimaryDark">#1565C0</item>--> <item name="colorAccent">#E91E63</item> </style>
第二步:同上一个第二步。
设置状态栏透明+颜色
mTintManager = new SystemBarTintManager(this);mTintManager.setStatusBarTintEnabled(true);mTintManager.setNavigationBarTintEnabled(true); mTintManager.setStatusBarTintResource(R.color.statusbar_bg);
第三步:
android:fitsSystemWindows=”true”
android:clipToPadding=”false”
1 0
- android沉浸式状态栏实现细节
- Android 沉浸式状态栏实现及细节处理
- Android沉浸式状态栏的细节
- android实现沉浸式状态栏
- Android 实现沉浸式状态栏
- android实现沉浸式状态栏
- Android 实现沉浸式状态栏
- Android沉浸式状态栏实现
- android沉浸式状态栏实现
- Android 实现沉浸式状态栏
- android沉浸式状态栏实现
- android沉浸式状态栏实现
- android状态栏实现沉浸式
- Android 实现沉浸式状态栏
- Android沉浸式状态栏实现
- Android实现沉浸式状态栏
- Android实现沉浸式状态栏
- android 沉浸式状态栏实现
- 架构师速成6.9-如何写好代码
- 【读书笔记】iOS-UIFont-动态下载系统提供的多种中文字体网址
- hdu 5317 多校第三场
- A20 操作GPIO口
- 用apache文件上传组件commons-io-2.4.jar commons-fileupload-1.2.1.jar进行文件上传
- android沉浸式状态栏实现细节
- Problem Killer(递推)
- json字符串转换为多级Map -list-map的形式
- 现代应用密码学中椭圆曲线求点集E以及点乘算法的java代码实现
- SQL Server 2008 Windows身份验证改为混合模式身份验证
- easyUI Tabs
- 通过JDBC/ODBC方法连接SQL Servers与MyEclipe(SQL)
- windows下Mysql解决Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
- 很好的网站