簡體   English   中英

android App顯示空白白屏,而不是啟動屏幕

[英]android App showing Blank white screen instead of splash screen

我已經花了幾個小時了...請有人在這里指出問題嗎?

這是我的價值觀/風格:

<resources>

    <!-- Base application theme. -->
    <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>
    </style>

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

    <style name="Theme.Transparent" parent="AppTheme">
        <item name="android:windowDisablePreview">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

這是我的清單文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nuku.mc.myfypapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.Transparent">
        <activity
            android:name=".SplashScreen"
            android:theme="@style/Theme.Transparent"
            android:label="@string/app_name"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan"
            />
        <activity
            android:name=".SignupActivity"
            android:windowSoftInputMode="adjustPan" />
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan" />
    </application>

</manifest>

這是應用程序splash_screen.xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/lin_lay"
    android:background="@android:color/holo_orange_dark">

    <ImageView
        android:layout_width="360dp"
        android:layout_height="480dp"
        android:id="@+id/imageView2"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:background="@android:color/holo_orange_dark"
        android:contentDescription="@string/splash_text"
        />
    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/splash_text"
        android:id="@+id/splashText"
        android:layout_marginBottom="150dp"
        android:layout_alignBottom="@+id/imageView2"
        android:layout_centerHorizontal="true"
        android:textStyle="bold|italic"
        android:focusable="true"
        android:textSize="@dimen/design_fab_image_size"
        android:textColor="#ffffff" />

</RelativeLayout>

這是splash.java

public class SplashScreen extends Activity {

    SessionManager manager;

    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Window window = getWindow();
        window.setFormat(PixelFormat.RGBA_8888);
    }

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);
        manager = new SessionManager();
        StartAnimations();
    }
    private void StartAnimations() {
        Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
        anim.reset();
        RelativeLayout l=(RelativeLayout) findViewById(R.id.lin_lay);
        l.clearAnimation();
        l.startAnimation(anim);

        anim = AnimationUtils.loadAnimation(this, R.anim.translate);
        anim.reset();
        ImageView iv = (ImageView) findViewById(R.id.imageView);
        iv.clearAnimation();
        iv.startAnimation(anim);

        Thread background = new Thread() {
            public void run() {

                try {
                    // Thread will sleep for 3 seconds
                    sleep(3*1000);

                    // After 5 seconds redirect to another intent
                    String status=manager.getPreferences(SplashScreen.this,"status");
                    Log.d("status",status);
                    if (status.equals("1")){
                        Intent i=new Intent(SplashScreen.this,MainActivity.class);
                        startActivity(i);
                    }else{
                       Intent i=new Intent(SplashScreen.this,LoginActivity.class);
                        startActivity(i);
                    }


                    //Remove activity
                    finish();

                } catch (Exception e) {

                }
            }
        };

        // start thread
        background.start();

    }
}

我已經遵循了五個以上的教程,但仍然無法解決問題

跟隨這篇文章 它清楚地說

啟動屏幕是在啟動UI之前屏幕顯示的內容,它是啟動活動的主題指定的窗口背景。 因此,我們需要的第一件事是啟動活動的特殊主題。

我通過遵循本文實現了啟動畫面。 因此,您無需創建任何初始屏幕活動。 只需將您的文本轉換為可繪制的資源,並將其用作啟動活動的初始屏幕主題中的背景即可。

唯一明顯的錯誤是您在onCreate中調用StartAnimations。 您想改為在onResume中執行此操作。 我還將嘗試將其分解為幾個步驟,以查看每個步驟是否都可以對其進行調試。 對我來說,第1步將默認背景設為紅色,然后查看它是否顯示出來。 然后,我嘗試將其設置為紅色的50%,以查看Alpha是否正常工作。 然后,我將嘗試一次測試您的動畫,首先是背景動畫,然后是翻譯動畫。 將其分解為更細小的部分,可以逐步解決該問題。

由於您是在onCreate中啟動動畫的,因此我猜測當前正在發生什么,因此您的動畫在首次渲染Activity之前已完成運行。 請記住,只有在onResume中,它才會呈現。 並且由於白色是活動的默認顏色,因此您看到的是白屏顯示幾秒鍾,然后是第二個活動。

另外,根據您希望背景淡入的設計,您需要在清單中為該活動設置的主題中設置android:background。 如果不這樣做,您將看到發生的情況(正確實施此操作時)為白色屏幕約0.5-2秒,然后出現白色,然后在開始運行初始屏幕動畫時變為透明。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM