• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

全屏沉浸式UI快速流程1

android 搞代码 3年前 (2022-03-02) 23次浏览 已收录 0个评论
文章目录[隐藏]

1.设置全屏

<code class="xml"><!-- 全屏-启动页最下面的各种状态栏也去掉,清单中启动Activity援用-->
    <style name="FullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>

<!--没有title,在application的theme中援用-->
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!--<item name="android:windowNoTitle">true</item>-->
    </style>
 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round" 
        android:supportsRtl="true"
        android:theme="@style/AppTheme"> //在这援用
        
<activity android:name=".StartActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:theme="@style/FullScreenTheme" //在这援用
            >   

2启动页倒计时跳转

https://gitee.com/hjmayun/codes/wofkb9z1y72e845xid0jg24

3 沉迷式状态栏

沉迷式状态栏最好不要从代码中设置,在代码中会有个变色的过程,不是想要的成果

1 新建两个文件夹values的 -v19,-v21的:

v19的styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--values-19. v19开始有android:windowTranslucentStatus这个属性,这个属性为将状态-->
    <style name="TranslucentStatusTheme" parent="AppTheme">
        <item name="android:windowTranslucentStatus">true</item>
    </style>
</resources>

v21的styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="TranslucentStatusTheme" parent="AppTheme">
         <item name="android:windowTranslucentStatus">false</item>
        <!--下部的导航栏也设置成沉迷-->
         <item name="android:windowTranslucentNavigation">true</item>
         <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <!-- Android 5.x开始须要把色彩设置通明,否则导航栏会出现零碎默认的浅灰色-->
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>

能够看到,零碎应用的都是TranslucentStatusTheme这个主题,只不过在不同api下他的属性有差异。

在values的style.xml下

我的AppTheme是NoActionBar的

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!--title(actionbar)的色彩-->
        <item name="colorPrimary">@color/black</item>
        <!--状态栏色彩-->
        <item name="colorPrimaryDark">@color/transparent</item>
        <!--浮动的button、光标色彩-->
        <item name="colorAccent">@color/bluelogin</item>
    </style>

写一个TranslucentStatusTheme,空实现就能够:

<style name="TranslucentStatusTheme" parent="AppTheme">
    </style>

2 在清单manifest.xml中,application援用这个主题即可

<code class="xml"> <application
        .....
        android:theme="@style/TranslucentStatusTheme">

3 留神

在layout的xml下的根布局须要增加属性:android:fitsSystemWindows=”true”

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    ....
    android:fitsSystemWindows="true"
   ....    >

增加这个属性之后,底下的导航栏才会有一个绝对的沉迷式的展现。

以上的沉迷成果最好别设置title,否则会有各种坑,计算起来很麻烦

4 参考

Android 沉迷式状态栏适配计划

android沉迷式状态栏、fitsSystemWindows、标题栏折叠


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:全屏沉浸式UI快速流程1

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址