2016-08-04 212 views
1

我已经在它几个小时了...请任何人都可以指出这个问题吗?android应用程序显示空白白色屏幕而不是闪屏

这是我的价值观/风格:

<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> 

这是溅。 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(); 

    } 
} 

我现在跟着五个以上的教程,仍然无法解决问题

回答

1

跟随this article。 上面清清楚楚地写着

闪屏就是屏幕显示之前,它是能够启动 充气的UI窗口的背景,此次推出 活动的主题指定。所以我们需要的第一件事情就是发起活动的一个特殊主题 。

我按照这篇文章实现了启动画面。所以你不需要创建任何启动画面活动。只需将您的文本转换为可绘制资源,并将其用作启动活动的启动画面主题的背景。

+0

感谢您分享文章 –

0

,看起来错得离谱是您的onCreate调用StartAnimations的唯一的事情。你想在onResume中做到这一点。我也会尝试将其分解成几个步骤,以查看每个步骤是否可以调试它。对我来说,第一步是默认背景,说红色,看看它是否出现。然后,我会尝试将其设置为50%红色,以查看Alpha是否正常工作。然后,我会尝试一次测试一个动画,首先是背景动画,然后是翻译动画。把它分解成更小的部分,可以让你更轻松地解决问题。

由于您在onCreate中开始动画,因此我猜测当前正在发生的事情是您的动画在第一次呈现Activity之前已完成运行。记住它不会渲染,直到在onResume。而且,由于白色是活动的默认颜色,所有您看到的只是几秒钟的白色屏幕显示,然后是第二个活动。

此外,在您希望背景淡入的设计中,您将需要在清单中设置为该活动的主题中设置android:background。如果你不这样做,你会看到发生的事情(当你正确地实现这个功能时)是一个大约.5-2秒的白色屏幕,然后在它开始运行你的启动画面动画时变成透明。

+0

谢谢,我将开始打破它,看看问题所在,谢谢 –

相关问题