安卓启动图去除顶部title和状态栏

1.在启动页的xml配置中,设置layout的id,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back"
    android:id="@+id/img_lay"
    tools:context="com.zhou.myapplication.LaunchImgActivity">
</LinearLayout>

2.在启动的activity类中加入如下代码:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.launch_img);
        //去除状态栏
        LinearLayout linearLayout =(LinearLayout)findViewById(R.id.img_lay);
        linearLayout.setSystemUiVisibility(View.INVISIBLE);  //设置不可见
        //延迟加载主页面
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(LaunchImgActivity.this, MainActivity.class);
                LaunchImgActivity.this.startActivity(intent);
                LaunchImgActivity.this.finish();

            }
        }, 2000);
    }

3.在style.xml中修改成如下代码,主要是把parent改为NoActionBar:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <!-- 沉浸式状态栏 -->
        <item name="android:fitsSystemWindows">true</item>
        <item name="android:clipToPadding">false</item>
    </style>

运行之后可以看到启动图全屏展示。

猜你喜欢

转载自www.cnblogs.com/phpzhou/p/9024388.html