美文网首页Android 开发知识
APP启动页和沉浸式状态栏设置

APP启动页和沉浸式状态栏设置

作者: hahauha | 来源:发表于2017-04-11 15:45 被阅读0次

    app启动页的正确设置
    方法一
    1、定义style

    <!--Base主题-->
        <style name="Base.App.Theme" parent="AppTheme">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>
    
    <!--启动界面主题-->
    <style name="App.Theme.Launch" parent="Base.App.Theme">
        <item name="android:windowBackground">@mipmap/welcome</item> 
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>
    

    welcome就是启动页图片
    2、引用

    <activity android:name=".main.LaunchActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait"
              android:theme="@style/App.Theme.Launch">  //引用
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
    
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    

    方法二
    方法一是在xml配置app启动图片,如果启动页图片需要动态配置,则使用方法二。
    只能设置activity的backgroud,但是启动有白屏或者黑屏闪现,无法避免,目前没有找到解决方法。
    1、设置activity根布局的background背景为welcome

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:background="@mipmap/welcome"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent">
    </LinearLayout>
    

    2、定义style

        <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>
    

    3、引用

    <activity android:name=".main.LaunchActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait"
              android:theme="@style/AppTheme.NoActionBar">  //引用
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
    
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    

    4、以上三步完成后,启动页的状态栏还是没有隐藏,达不到全屏的效果。所以需要在LaunchActiivty的onCreate()方法中做如下设置,隐藏状态栏

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            //隐藏状态栏
            this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setContentView(R.layout.activity_launch);
            getUpdateInfo();
        }
    

    状态栏沉浸式设置
    http://blog.csdn.net/fan7983377/article/details/51604657
    http://www.androidchina.net/4715.html

    相关文章

      网友评论

        本文标题:APP启动页和沉浸式状态栏设置

        本文链接:https://www.haomeiwen.com/subject/zchuattx.html