网上是有好多的实现方式,也有具体的代码,每个人总能找到适合自己的,感觉自己能用的方式来实现这些功能

先看效果,

Android 标题栏沉浸式的实现_第1张图片

步骤1,设置Application的theme  这个theme会使你NoTitlebar 也没有状态栏 全部都是你的布局 从头到尾 我比较喜欢这种方式

android:theme="@style/AppTheme"

<?xml version="1.0" encoding="UTF-8" ?><resources>        <style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar.TranslucentDecor" type="text/css">        style>    resources>


步骤二,

在你要沉浸的布局中加

android:clipToPadding="true"android:fitsSystemWindows="true"
这两句话 这其中 是有一个问题的 因为你加了这两句话之后 你的那个布局成了 从一开始最上面到最下面 也就是 你布局整体向上提了标题栏的高度

这个问题怎么解决 直接用paddingtop="25dp" 我们美工说的标题栏的高度一般都是50px 所以适配就是25dp 同时 你把的最上面的布局扩大25dp    具体实现 看下面的代码

<?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="95dp"    android:clipToPadding="true"    android:fitsSystemWindows="true"    android:paddingTop="25dp"    android:background="#af4752"    ><TextView    android:layout_width="match_parent"    android:layout_height="match_parent"    android:text="你问我爱你有多深!"    android:textSize="40dp"    android:gravity="center"    />LinearLayout>

如此 我自己认为可以的沉浸式的标题栏完成,这种实现方式灵活多变,自定义的成分比较高,比较推荐....额,虽然我只是知道这一种





更多相关文章

  1. Android 中LayoutInflater(布局加载器)之实战篇
  2. Android启动界面优化技巧-Splash Screens的正确方式
  3. 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、
  4. Android布局之相对布局——RelativeLayout
  5. 【Android 初学】3、控件布局初步
  6. Android ListView中点击单行实现RadioButton的单选功能,自定义Ite
  7. android五种布局-霓虹灯效果实现
  8. Android的两种数据存储方式分析(二)
  9. Android TextView 添加下划线的几种方式

随机推荐

  1. Android 下拉刷新框架实现
  2. 关于getting 'android:label' attribute:
  3. ffmpeg 移植到 android
  4. Android网易评论盖楼效果实现
  5. Android 用自定义PopupWindow实现自定义T
  6. Android进程级别与如何防止服务进程被回
  7. android 键盘快捷指令
  8. [置顶] 推翻自己和过往,重学自定义View
  9. android弹出框
  10. Android(安卓)6.0 ContextCompat中不包含