android values-v21 style 报错,Android 4.4 以上实现透明导航栏和状态栏 Translucent system bar...
第一种方式
第一种方式,需要做下面三步设置
1、在values、values-v19、values-v21的style.xml都设置一个 Translucent System Bar 风格的Theme
values/style.xml
values-v19/style.xml
true
true
values-v21/style.xml
false
true
@android:color/transparent
上面需要注意的地方是,无论你在哪个SDK版本的values目录下,设置了主题,都应该在最基本的values下设置一个同名的主题。这样才能确保你的app能够正常运行在 Android 4.4 以下的设备。否则,肯定会报找不到Theme的错误。
2、在AndroidManifest.xml中对指定Activity的theme进行设置
android:name=".ui.ImageTranslucentBarActivity"
android:label="@string/image_translucent_bar"
android:theme="@style/ImageTranslucentTheme" />
3、在Activity的布局文件中设置背景图片,同时,需要把android:fitsSystemWindows设置为true
activity_image_translucent_bar.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/env_bg"
android:fitsSystemWindows="true">
到此,第一种实现方式完成,大家可以看看下面的效果
ImageTranslucentTheme效果
就跟中华万年历的天气预报效果界面一样,系统的整个导航栏都融入了app的界面中,背景图片填满了整个屏幕,看起来舒服很多。这里还有一个android:fitsSystemWindows设置需要注意的地方,后面会在细讲。接下来看第二种实现。
方式二
相比中华万年历,QQ音乐采用的是另外一种实现的方式,它将app的Tab栏和系统导航栏分开来设置。
QQ音乐效果风格
由于它的Tab栏是纯色的,所以只要把系统通知栏的颜色设置和Tab栏的颜色一致即可,实现上相比方法一要简单很多。同样要到不同SDK版本的values下,创建一个同名的theme,在values-v21下,需要设置系统导航栏的颜色:
values-v21/style.xml
false
true
@color/color_31c27c
再到ColorTranslucentBarActivity的布局文件activity_color_translucent_bar.xml中设置Tab栏的颜色
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="@color/color_31c27c">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="QQ Music"
android:textColor="@android:color/white"
android:textSize="20sp" />
到此,我们就可以得到和QQ音乐主界面一样的效果了。
QQ音乐界面实现效果
到此,就大体介绍完了 Translucent System Bar 的两种实现方式了。
android:fitsSystemWindows的“踩坑”
通过前面的两种方式,大家估计会留意到一个地方,就是所有实现 Translucent System Bar 效果的Activity,都需要在根布局里设置 android:fitsSystemWindows="true" 。设置了该属性的作用在于,不会让系统导航栏和我们app的UI重叠,导致交互问题。这样说可能比较抽象,看看下面两个效果图的对比就知道了。
有fitsSystemWindows设置
没有fitsSystemWindows设置
还有需要注意用到Translucent system bar时,activity的顶层布局必须是基本的布局,比如,如果直接用material design里面的CoordinatorLayout做顶层布局时,会出现一些异常问题。
android values-v21 style 报错,Android 4.4 以上实现透明导航栏和状态栏 Translucent system bar...相关推荐
- Android打电话功能权限报错,Android实现简单的拨号器功能
简易拨号器的制作方法,具体如下 一.布局构造 android:layout_width="match_parent" android:layout_height="mat ...
- Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法
Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法 参考文章: (1)Failed to resolve: com.andr ...
- Xamarin Android真机测试报错
Xamarin Android真机测试报错 Xamarin Android真机测试报错,错误信息为INSTALL_CANCELLED_BY_USER.出现这个错误,通常都是真机上开发者选项设置错误.由 ...
- 【错误记录】Android Studio 配置 AspectJ 报错 ( all buildscript {} blocks must appear before any plugins {} )
文章目录 一.报错信息 二.解决方案 一.报错信息 在 Android Studio 配置 AspectJ 报错 : Build file 'D:\002_Project\002_Android_Le ...
- 【错误记录】反射内部类报错 ( Android 使用 Hook 时反射内部类报错 )
文章目录 一.报错信息 二.解决方案 一.报错信息 使用场景 : 需要 Hook 住 View 的 OnClickListener 点击方法 , 该监听器在 View 的内部类 ListenerInf ...
- android 启动service报错,Android小经验
转载自:http://mp.weixin.qq.com/s?__biz=MzA4MjU5NTY0NA==&mid=404388098&idx=1&sn=8bbbba7692dc ...
- Android Studio support 26.0.0-alpha1 Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法
Android Studio support 26.0.0-alpha1 Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法 ...
- android studio 自动引用,Android Studio三方引用报错但是项目可以运行的解决方案
Android Studio第一次启动的Fetching android sdk component information的问题 1)进入刚安装的Android Studio目录下的bin目录.找到 ...
- Unity集成穿山甲后打包报错android:networkSecurityConfig , Picked up JAVA_TOOL_OPTIONS:-Dfile.encoding=UTF-8
Unity集成穿山甲4.0SDK后打包报错 , /Users/-/Temp/gradleOut/unityLibrary/src/main/AndroidManifest.xml:31:3-138:1 ...
最新文章
- c#_序列化与反序列化的应用
- Expo大作战(十九)--expo打包后,发布分用程序到商店的注意事项
- 【自动驾驶】3. DDS 数据分发服务(Data Distribution Service)
- Table 自动换行问题
- linux下永久添加静态路由
- python中的运算符_Python中的运算符
- js 字符串插入_Vue.js 条件与循环
- 农用圆形打捆机行业调研报告 - 市场现状分析与发展前景预测
- 拓端tecdat|R语言时间序列TAR阈值自回归模型
- latex公式符号大全
- 短信跳转到微信关注公众号的方案
- 雷特智能家居龙海祁:从专业调光到全宅智能,20年专注成就专业
- 学习进度2012-6-26(动态规划算法、Prim算法、Dijkstra算法)
- 水果店收银系统解决方案
- SLCP验厂辅导,工厂进行社会劳工整合项目(SLCP认证)验证的具体步骤是
- 学习《Redis设计与实现》Chapter1
- C语言中的atoi函数的实现
- 单模光纤与多模光纤区别
- Word插入希腊字母及特殊符号 分类整
- 什么是常识?一个人独立生活所具备的能力