コールドスタートビジュアル最適化
13264 ワード
文書ディレクトリ劉海屏表示モード を指定する定義トピックtheme theme構成関連属性 は、前髪スクリーン&浸透レイアウト まで拡張可能 drawable設計layer-list方式 AndroidManifest定義theme
drawableフォルダのstyle.xml
drawable-v 28の下のstyle.xmlはAndroid 9対応の前髪スクリーンに使用
drawable_splash.xmlは冷間起動の背景を定義し,適合のためにlayer-listを用いる
前髪画面表示モードの指定
Googleは劉海屏の表示方式に3種類の表示モードを提供した.
style.xmlでthemeプロパティを構成する
コードでの指定
<activity
android:name=".modules.welcome.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
intent-filter>
activity>
drawableフォルダのstyle.xml
<style name="SplashTheme" parent="AppTheme">
- "android:background"
>@drawable/drawable_splash
- "windowNoTitle">true
- "android:windowAnimationStyle">@null
- "android:windowFullscreen">true
style>
drawable-v 28の下のstyle.xmlはAndroid 9対応の前髪スクリーンに使用
<style name="SplashTheme" parent="AppTheme">
- "android:background"
>@drawable/drawable_splash
- "windowNoTitle">true
- "android:windowAnimationStyle">@null
- "android:windowFullscreen">true
- "android:windowDrawsSystemBarBackgrounds">false
- "android:windowTranslucentNavigation">true
- "android:windowLayoutInDisplayCutoutMode">shortEdges
style>
drawable_splash.xmlは冷間起動の背景を定義し,適合のためにlayer-listを用いる
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/common_white_color" />
item>
<item android:bottom="175dp">
<bitmap
android:gravity="center_vertical|left"
android:src="@drawable/pic_splash_icon" />
item>
<item android:bottom="50dp">
<bitmap
android:gravity="center_horizontal|bottom"
android:src="@drawable/pic_splash_logo" />
item>
layer-list>
前髪画面表示モードの指定
Googleは劉海屏の表示方式に3種類の表示モードを提供した.
// , ,
public static final int LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT = 0;
//
public static final int LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES = 1;
//
public static final int LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER = 2;
style.xmlでthemeプロパティを構成する
<item name="android:windowLayoutInDisplayCutoutMode">shortEdgesitem>
コードでの指定
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
getWindow().setAttributes(lp);
}