Android 标题栏沉浸式的实现

来源:互联网 发布:手机版ps软件 编辑:程序博客网 时间:2024/06/05 21:11

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

先看效果,


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

android:theme="@style/AppTheme"

<?xml version="1.0" encoding="UTF-8" ?><resources>    <!-- Application theme. -->    <style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar.TranslucentDecor" type="text/css">        <!-- All customizations that are NOT specific to a particular API-level can go here. --></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>

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





0 0
原创粉丝点击