当前位置: 移动技术网 > IT编程>开发语言>.net > Android 启动页全面屏的适配

Android 启动页全面屏的适配

2020年09月29日  | 移动技术网IT编程  | 我要评论
启动页全面屏的适配为了能够避免一个短暂的黑屏或白屏现象,我们都会在闪屏页面(或者启动页面)的theme上加上一张背景图。但是如果不适配,在全面屏的手机上会有拉伸的现象。解决方法1.在清单文件中配置,全面屏的一些参数 <!-- 允许绘制到oppo、vivo刘海屏机型的刘海区域 --> <meta-data android:name="android.max_aspect" android:value="2.

启动页全面屏的适配

为了能够避免一个短暂的黑屏或白屏现象,我们都会在闪屏页面(或者启动页面)的theme上加上一张背景图。但是如果不适配,在全面屏的手机上会有拉伸的现象。

解决方法

1.在清单文件中配置,全面屏的一些参数

        <!-- 允许绘制到oppo、vivo刘海屏机型的刘海区域 -->
        <meta-data
            android:name="android.max_aspect"
            android:value="2.2" /> <!-- 允许绘制到华为刘海屏机型的刘海区域 -->
        <meta-data
            android:name="android.notch_support"
            android:value="true" /> <!-- 允许绘制到小米刘海屏机型的刘海区域 -->

2.创建多个style文件(注意的sdk版本要是高版本的)
在这里插入图片描述
普通style

    <style name="AppTheme.FullTheme" >
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@drawable/splash_bg</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

style21

    <style name="AppTheme.FullTheme">
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <!--windowTranslucentNavigation这个属性设置成true,则navigationBarColor设置会失效-->
        <!--<item name="android:windowTranslucentNavigation">false</item>-->
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@drawable/splash_bg</item>
        <!--不让windowBackground延申到navigation bar区域-->
        <item name="android:windowDrawsSystemBarBackgrounds">false</item>

    </style>

style28

   <style name="AppTheme.FullTheme">
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <!--windowTranslucentNavigation这个属性设置成true,则navigationBarColor设置会失效-->
        <!--<item name="android:windowTranslucentNavigation">false</item>-->
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@drawable/splash_bg</item>
        <!--不让windowBackground延申到navigation bar区域-->
        <item name="android:windowDrawsSystemBarBackgrounds">false</item>
        <!--适配Android P刘海屏-->
        <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>

    </style>

3.在drawable目录下创建一个xml文件

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="MissingDefaultResource">


    <item>
        <shape>
            <solid android:color="@android:color/transparent"/>
        </shape>
    </item>



    <item>
        <bitmap
            android:src="@mipmap/icon_splash_new_bg"
            android:gravity="fill"
            android:tileMode="disabled"
            />
    </item>
</layer-list>

4.创建一个drawable-xxhdpi-2034x1080(或者mipmap-xxhdpi-2034x1080)资源文件夹放18:9的图片
5.在你的启动Activity中加入下面的判断,你的Activtiy的theme引用style文件中的主题


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            decorView.setSystemUiVisibility(option);
            getWindow().setNavigationBarColor(Color.TRANSPARENT);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }

本文地址:https://blog.csdn.net/u013467495/article/details/108870164

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网