4.4适配沉浸式详解
来源:互联网 发布:php implode 什么意思 编辑:程序博客网 时间:2024/06/16 06:32
4.4适配沉浸式
values/colors.xml
<?xml version="1.0" encoding="utf-8"?><resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color></resources>
values/styles.xml
<!-- Base application theme. --> <style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="AppTheme" parent="@style/BaseTheme"> </style>
values-v19/styles.xml
<resources> <style name="AppTheme" parent="@style/BaseTheme"> <item name="android:windowTranslucentStatus">true</item> </style></resources>
values-v21/styles.xml
<resources> <style name="AppTheme" parent="@style/BaseTheme"> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">@android:color/transparent</item> </style></resources>
布局文件
layout/app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="com.example.fullstack.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <include layout="@layout/content_main" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:src="@android:drawable/ic_dialog_email" /></android.support.design.widget.CoordinatorLayout>
layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" tools:openDrawer="start"> <include layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" /></android.support.v4.widget.DrawerLayout>
*注意点:
- NavigationView不设置android:fitsSystemWindows=”true”
- CoordinatorLayout设置android:fitsSystemWindows=”true”
- values-v21下设置Theme属性android:statusBarColor为透明
Activity代码
使用SystemBarTintManager(https://github.com/jgilfelt/SystemBarTint),设置状态栏颜色
注:
5.0以上Android版本会自动适配,theme主题中的属性,不需要额外适配。
if(Build.VERSION.SDK_INT==Build.VERSION_CODES.KITKAT){ SystemBarTintManager systemBarTintManager=new SystemBarTintManager(this); systemBarTintManager.setStatusBarTintEnabled(true); systemBarTintManager.setStatusBarTintResource(statusBarColor); systemBarTintManager.setNavigationBarAlpha(0.2f); }
如果当前Android版本等于4.4,使用SystemBarTintManager适配。
0 0
- 4.4适配沉浸式详解
- android沉浸式布局详解
- mui 沉浸式状态栏详解
- Android沉浸式(透明)状态栏适配
- 详解安卓沉浸式状态栏
- Android中沉浸式状态栏详解
- Android 沉浸式状态栏和侧滑栏--详解
- 简单易懂的沉浸式状态栏使用详解(1)——状态栏全透明(含虚拟按键适配)
- 4.4以上android沉浸式
- 创建沉浸式状态栏及兼容性适配
- Android 虚拟按键与沉浸式的适配
- 沉浸式状态栏适配不同的版本
- 沉浸式状态栏适配不同的版本
- 国际化饥和屏幕适配 沉浸式
- 关于MIUI 9沉浸式状态栏的最新适配
- 初学者---Android 沉浸式(透明)状态栏适配
- 沉浸式
- 沉浸式
- Xcode 6怎么创建Category文件
- JAVA 虚拟机字节码执行
- Macbook全系列详细分析及购机指南
- 小白学算法2.2——选择排序
- 《leetCode》:Unique Paths II
- 4.4适配沉浸式详解
- linux下安装lamp,php无法识别配置文件路径
- EM算法解决GMM问题
- SQL
- mysql数据库 SQL查询语句优化和一些注意
- [Xcode] The iPhone simulator do not have home button
- js实现返回上一url
- linux 初体验
- 整个linux系统的备份和还原的方法