Android?App實(shí)現(xiàn)閃屏頁廣告圖的全屏顯示實(shí)例
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)文章
Android 通過ViewHolder優(yōu)化適配器的實(shí)現(xiàn)方法(必看)
下面小編就為大家?guī)硪黄狝ndroid 通過ViewHolder優(yōu)化適配器的實(shí)現(xiàn)方法(必看)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04Android開發(fā)之InetAddress基礎(chǔ)入門簡介與源碼實(shí)例
這篇文章主要介紹了Android開發(fā)之InetAddress基礎(chǔ)入門簡介,需要的朋友可以參考下2020-03-03鴻蒙手機(jī)版JNI實(shí)戰(zhàn)案例解析(JNI開發(fā)、SO庫生成、SO庫使用)
這篇文章主要介紹了鴻蒙手機(jī)版JNI實(shí)戰(zhàn)(JNI開發(fā)、SO庫生成、SO庫使用)的相關(guān)資料,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04Android重寫View實(shí)現(xiàn)全新的控件
這篇文章主要介紹了Android重寫View來實(shí)現(xiàn)全新的控件,最難的一種自定義控件形式,感興趣的小伙伴們可以參考一下2016-05-05React-Native中使用驗(yàn)證碼倒計(jì)時(shí)的按鈕實(shí)例代碼
這篇文章主要介紹了React-Native中使用驗(yàn)證碼倒計(jì)時(shí)的按鈕實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下2017-04-04