72、android状态栏一体化,状态栏改变颜色
2016-01-11 16:14
447 查看
只能在4.4以上版本使用。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#6699ff" android:clipToPadding="true" android:fitsSystemWindows="true" android:orientation="vertical" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="50dp" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="标题" android:textColor="#ffffff" android:textSize="20sp" /> </RelativeLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:gravity="center" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World" android:textColor="#000000" android:textSize="28sp" android:textStyle="italic" /> </LinearLayout> </LinearLayout>
android:clipToPadding="true" clipToPadding:控件的绘制区域是否在padding里面, 值为true时padding那么绘制的区域就不包括padding区域; android:fitsSystemWindows="true"
设置应用布局时是否考虑系统窗口布局;如果为true,将调整系统窗口布局以适应你自定义的布局。比如系统有状态栏,应用也有状态栏时。 看你这个布局代码,恰恰是在定义标题栏样式,所以用到这行代码了。
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //判断当前SDK版本号,如果是4.4以上,就是支持沉浸式状态栏的 if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } }
相关文章推荐
- Android中setLayoutParams要用父控件的LayoutParams
- 如何判断是否得到"android.permission.PACKAGE_USAGE_STATS"权限
- 最简单也最难——如何获取到Android控件的高度,获取android控件
- 另外两种Android沉浸式状态栏实现思路
- android studio 修改默认的 debug.keystore
- ANDROID版本号和版本名称
- Android中Service的使用详解和注意点(LocalService)
- Android实现波浪线效果(xml bitmap)
- android ndk c编译
- android中用setBackgroundResource加载图片时出现oom
- Android 删除无用Java文件
- Android之 环境搭建
- Gson解析null替换为空字符串
- Android Studio——如何将AndroidStudio的项目提交到Github上
- android游戏中关卡式背景是怎么做出来的
- 读书笔记------android图片加载
- android图片处理方法
- [Android]对MVC和MVP的总结
- Android异常之 unable to write jarlist cache file
- android 遇到的小问题解决集合