关于沉浸式,相信大家也都有了解,下面记录下一个简单实现沉浸式的方法。(4.4以上)

在setContentView 前面调用以下方法。

private void initState() {        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {            //透明状态栏            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);            //透明导航栏            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);        }    }

并在layout 的布局中添加两行代码

        android:fitsSystemWindows="true"        android:clipToPadding="true"

这两行代码一定要放在布局文件中的第一个容器(状态栏下面第一个容器)中如下就是放在RelativeLayout中:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent"    >    <RelativeLayout        android:fitsSystemWindows="true"        android:clipToPadding="true"        android:layout_width="match_parent"        android:layout_height="50dp"        android:orientation="horizontal"        android:background="@color/bule2">        <ImageView            android:id="@+id/backIv"            android:layout_width="25dp"            android:layout_height="match_parent"            android:layout_gravity="center"            android:layout_marginLeft="15dp"            android:src="@drawable/back"            />        <TextView            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_gravity="center"            android:gravity="center"            android:textSize="20sp"            android:textColor="@color/white"            android:text="@string/showdata"/>    RelativeLayout>LinearLayout>

更多相关文章

  1. Android(安卓)4.0.1_r1源代码发布,更新获取方法
  2. 6.1.5 GridView详解编辑
  3. Android中使用lambda表达式
  4. Android中JNI高级应用 - 本地C代码中创建Java对象及本地JNI对象
  5. Android培训班(31)
  6. android关闭整个应用程序
  7. android中获取string字符串的方法
  8. Android底部导航栏最常用的两种写法
  9. android 在连拍菜单中,增加连拍张数选项

随机推荐

  1. Android中TextView如何实现水平和垂直滚
  2. android系统自带的主题与样式(theme and
  3. Android(安卓)xml资源文件中@、@android:
  4. Android中对NFC的实现代码分布在如下几个
  5. android 使控件透明
  6. Android(安卓)存储选项之 ContentProvide
  7. android定位布局
  8. Android(安卓)Camera 使用小结
  9. android layout_weight了解
  10. android自定义view属性