android标题栏沉浸效果

android4.4开始实现了状态栏的沉浸,即状态栏一体化,效果如图:

下面来看实现步骤:
首先,你需要在value-19中的style.xml中添加以下属性:

 

然后在AnroidManifest.xml中application标签中添加android:theme=”@style/AppTheme”即可,这样你就可以在android4.4以上的系统中运行就会出现上图的效果,但是你会发现你的布局会与状态栏重叠,这样就会导致状态栏会遮挡,解决这种问题只需要在你的activity的布局文件中添加android:fitsSystemWindows=”true”属性,如下:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:background="@color/default_color"    android:fitsSystemWindows="true">

这样就可以避免状态栏的遮挡,在测试中发现,当运行在android4.4以下的系统上时,会发现会多出actionbar,解决这个问题也很简单,只需要在values文件夹下的style.xml中添加name=”android:windowNoTitle”>true即可,如下:

    <style name="AppTheme" parent="BaseAppTheme">        -- All customizations that are NOT specific to a particular API-level can go here. -->     <item name="android:windowNoTitle">trueitem>       style>

或者直接设置parent为一个带有windowNoTitle的theme,例如parent=”Theme.AppCompat.Light.NoActionBar”

另外,除了以上修改style.xml的方法之后,也可以在activity中直接实现,代码如下:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {    Window window = getWindow();    // Translucent status bar    window.setFlags(        WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,        WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);}

至此,状态栏的沉浸就完成了,在开发中可能有一些要求,比如状态栏的颜色要比应用的主题的颜色要深一些等,这种问题有不同的解决办法,这里就不说了。另外,在测试中发现,在不同的系统上状态栏的沉浸效果还是不一样的,比如说6.0系统的状态栏要比背景颜色深很多,而5.0,4.4的系统状态栏与背景颜色就基本上相同,具体不同的系统所表现的不同的表现并没有做过多测试。

更多相关文章

  1. android selector
  2. Android(安卓)图像处理(一) : Shader
  3. android 将程序设置为app2sd
  4. Android驱动使用JNI调用
  5. Android记事本NotePad应用功能拓展(六)
  6. Android(安卓)L添加kk版的OOBE开机向导
  7. Android(安卓)TabHost学习笔记
  8. 基于ffmpeg的Android播放器开源代码
  9. Android实现输入手机号时自动添加空格

随机推荐

  1. android 列出所有播放器
  2. android 编译库过程
  3. WebView 无法执行js代码
  4. 如何取得android手机网络信息
  5. Checkbox(打勾显示输入的密码)
  6. Gallery組件學習总结及OutOfMemoryError:
  7. 修改软键盘的回车键为发送键
  8. android ImageView实现图片浏览器(点击左
  9. android heapStartSize heapMaximumSize
  10. android fastboot flash system 失败