欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android?App實(shí)現(xiàn)閃屏頁廣告圖的全屏顯示實(shí)例

 更新時(shí)間:2022年09月06日 11:14:57   作者:碧水逍遙  
這篇文章主要為大家介紹了Android?App實(shí)現(xiàn)閃屏頁廣告圖的全屏顯示實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

1. 適配長屏幕的全面屏

至于全屏展示,就得做適配工作,有以下兩種方式可進(jìn)行適配:

  • 在 Android 8.0(API 26)及更高版本中,我們可以在 標(biāo)簽中使用 android:MaxAspectRatio 來聲明其支持的屏幕最大寬高比。
  • 比如我們可以聲明最大寬高比為 2.4:
<!-- Render on full screen up to screen aspect ratio of 2.4 -->
<!-- Use a letterbox on screens larger than 2.4 -->
<activity android:maxAspectRatio="2.4">
 ...
</activity>
  • 對(duì)于Android 7.1及更低版本,我們可以在 元素中添加名為 android.max_aspect 的 元素

如下所示:

<!-- Render on full screen up to screen aspect ratio of 2.4 -->
<!-- Use a letterbox on screens larger than 2.4 -->
<meta-data android:name="android.max_aspect" android:value="2.4" />

2. 適配劉海屏或者水滴屏

Google 為劉海屏顯示方式提供了三種顯示模式:

// 默認(rèn)情況,全屏頁面不可用劉海區(qū)域,非全屏頁面可以進(jìn)行使用
public static final int LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT = 0;
// 允許頁面延伸到劉海區(qū)域
public static final int LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES = 1;
// 不允許使用劉海區(qū)域
public static final int LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER = 2;

凹形屏幕的顯示模式

我們可以通過下面兩種方式來指定應(yīng)用在凹形屏幕的顯示模式:

  • 在主題中加入android:windowLayoutInDisplayCutoutMode 屬性指定顯示模式:
// value-v28/styles.xml
 <style name="AppTheme.Launcher" parent="AppTheme">
        <item name="android:windowBackground">@drawable/branded_launch_screens</item>
        <item name="android:statusBarColor">@color/colorPrimary</item>
        <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
  • 通過在代碼中指定 Activity 的顯示模式

我們可以在 Activity 的 onCreate 中指定凹形屏幕的顯示模式:

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= 28) {
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
            getWindow().setAttributes(lp);
        }
}

具體使用:需要在values-v27及以上的styles.xml中加入以下主題設(shè)置:

<!--實(shí)現(xiàn)啟動(dòng)頁全屏-->
<style name="Theme.SplashActivity" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@color/white</item>
    <item name="android:windowTranslucentStatus">false</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="colorPrimary">@color/main_bg</item>
    <item name="colorPrimaryDark">@color/white</item>
    <item name="colorAccent">@color/white</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>

以上就是Android App實(shí)現(xiàn)閃屏頁廣告圖的全屏顯示實(shí)例的詳細(xì)內(nèi)容,更多關(guān)于Android 閃屏頁廣告圖全屏的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論