Android启动页适配导航栏,Android P 启动页适配适配刘海屏

需求: app 启动页全屏,延伸到刘海屏的状态栏和底部的导航栏,操作步骤如下:

app 的 build.gradle 配置

注意 compileSdkVersion、buildToolsVersion、targetSdkVersion 都是 30

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {

compileSdkVersion 30

buildToolsVersion "30.0.2"

defaultConfig {

applicationId "com.toys.testimmersionbar"

minSdkVersion 21

targetSdkVersion 30

versionCode 1

versionName "1.0"

}

buildTypes {

release {

minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

}

}

}

dependencies {

implementation fileTree(dir: "libs", include: ["*.jar"])

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation 'androidx.core:core-ktx:1.3.2'

implementation 'androidx.appcompat:appcompat:1.2.0'

implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

api 'com.gyf.barlibrary:barlibrary:2.3.0'

implementation 'com.google.android.material:material:1.1.0-alpha05'

}

启动页 SplashActivity 代码

注意: SplashActivity 不需要 setContentView( )

class SplashActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

// setContentView(R.layout.activity_splash3)

supportRequestWindowFeature(Window.FEATURE_NO_TITLE)

StatusBarCompat.setTranslucentDiff(this)

StatusBarCompat.setNavigationBarTransparent(this)

Handler().postDelayed({

startActivity(Intent(this, MainActivity::class.java))

}, 3000)

}

}

AndroidManifest.xml 配置

package="com.toys.testimmersionbar">

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"

>

android:name=".activity.SplashActivity3"

android:screenOrientation="portrait"

android:theme="@style/AppTheme.Splash">

android:name="android.notch_support"

android:value="true" />

styles.xml

@color/colorPrimary

@color/colorPrimaryDark

@color/colorAccent

@color/white

@color/white

@color/white

false

true

@drawable/splash_logo_bg

false

@android:color/transparent

splash_logo_bg.xml

android:opacity="opaque">

android:top="227dp">

android:gravity="top"

android:src="@drawable/mc_forum_face234" />

splash_logo_bg.xml 的预览效果如下:

8b331c7f5c15

image

最终效果预览

8b331c7f5c15

image

可见启动页完全全屏了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值