Android 标题栏沉浸式的实现
16lz
2021-01-23
网上是有好多的实现方式,也有具体的代码,每个人总能找到适合自己的,感觉自己能用的方式来实现这些功能
先看效果,
步骤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>
如此 我自己认为可以的沉浸式的标题栏完成,这种实现方式灵活多变,自定义的成分比较高,比较推荐....额,虽然我只是知道这一种
更多相关文章
- Android 中LayoutInflater(布局加载器)之实战篇
- Android启动界面优化技巧-Splash Screens的正确方式
- 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、
- Android布局之相对布局——RelativeLayout
- 【Android 初学】3、控件布局初步
- Android ListView中点击单行实现RadioButton的单选功能,自定义Ite
- android五种布局-霓虹灯效果实现
- Android的两种数据存储方式分析(二)
- Android TextView 添加下划线的几种方式