1

嗨,请查看附件视频以了解问题

视频

闪屏活动

    public class SplashScreenActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.splash);

        findViewById(R.id.txt_skip).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
            }
        });
    }

}

主要活动

    public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

风格

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<!-- Theme for Splash with no Action bar full screen -->
<style name="splash_screen" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

样式/v21

<?xml version="1.0" encoding="utf-8"?>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
</style>

显现

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".SplashScreenActivity"
        android:theme="@style/splash_screen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".MainActivity"
        android:configChanges="keyboard|keyboardHidden|orientation"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme" />

</application>

活动主:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


    <TextView
        android:id="@+id/toolbar_title"
        style="@android:style/TextAppearance.Large"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Demo App"
        android:textColor="@android:color/white" />

</android.support.v7.widget.Toolbar>

谁能帮我解决这个问题??

4

1 回答 1

1

我尝试了您的代码,发现当MainActivitySplashActivity中单击跳过按钮后打开时,系统开始绘制状态栏但不是立即开始,因为它在一些动画中打开,直到那时MainActivity布局让整个屏幕画布自行绘制。之后尝试了几分钟来修复主题或样式,但我没有成功,我想出了一个技巧,在启动MainActivity之前显示状态栏,这样MainActivity的布局就不会获得全屏画布来绘制自身。

你也可以试试这个技巧。

public class SplashScreenActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.splash);

        findViewById(R.id.txt_skip).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT > 16) {
                    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                }
                else {                       
                    int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
                    getWindow().getDecorView().decorView.setSystemUiVisibility(uiOptions);
                }                
                startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
            }
        });
    }
}

希望这对您有所帮助。让我知道这是否解决了您的问题?

于 2016-02-26T10:57:08.003 回答