今天要记录的是Android沉浸式状态栏的开发,看到别的应用都有沉浸式状态栏,是不是感觉很爽,今天我也来做一个沉浸式状态栏的例子,下面看一下效果图:

下面记录一下实现过程:
1、首先在需要使用沉浸式状态栏的Activity里,加上如下代码:

requestWindowFeature(Window.FEATURE_NO_TITLE);        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);         }  

2.修改Activity对应的布局文件,加上两个属性,如下代码所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="true" android:fitsSystemWindows="true" android:background="#6699ff" android:orientation="vertical">

就这俩个代码就能实现沉浸式状态栏,稍后我会把代码链接弄上来。
代码下载

更多相关文章

  1. Android用代码实现EditText不可编辑
  2. Android中webview跟JAVASCRIPT中的交互
  3. Android非Kotlin支持项目添加Kotlin代码时的注意点
  4. android 设置透明度 标题栏 窗体透明
  5. 利用androidannotations的@Rest注解替换Spring Android(安卓)Res
  6. Android(安卓)本地代码中的LIKELY和UNLIKELY宏
  7. Android利用setLayoutParams在代码中调整布局(Margin和居中)
  8. 我的Android进阶之旅------>Android百度地图定位SDK功能学习
  9. android通用文件操作

随机推荐

  1. Android 网页加载完成ProgressDialog运用
  2. Android CheckBox使密码可见/隐藏
  3. How to add custom title bar to android
  4. Android悬浮框
  5. Android 8.0新特性调研
  6. android ImageView的scaleType属性
  7. Android Studio UI布局
  8. [转帖] android平台刷机包的制作研究 1~2
  9. android View onMeasure
  10. Android Studio使用org.apache.http报错