2016-08-04 4 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에서 그렇게하고 싶습니다. 나는 또한 이것을 단계별로 분해하여 각 단계가 디버깅을하는지 확인하려고한다. 나를 위해 1 단계는 빨간색으로 말하고 배경이 보이는지를 알기 위해 배경을 기본값으로 설정합니다. 그런 다음 알파가 올바르게 작동하는지 확인하기 위해 빨간색으로 50 %로 설정하려고합니다. 그런 다음 애니메이션을 한 번에 하나씩 테스트 해 봅니다. 배경 애니메이션과 번역 애니메이션이 차례로 있습니다. 이를 작은 조각으로 분해하면 연속적으로 작업하여 더 쉽게 해결할 수 있습니다.

애니메이션을 시작하면 내 생각에 현재 무슨 일이 일어나고 있는지 처음부터 활동이 렌더링되기 전에 애니메이션이 끝났다고 생각됩니다. onResume에서 렌더링 될 때까지 렌더링되지 않는다는 것을 기억하십시오. 그리고 흰색은 활동의 기본 색상이기 때문에 몇 초 동안 흰색 화면이 표시되고 두 번째 활동이 표시됩니다.

또한 배경을 페이드 인하려는 디자인이 주어지면 매니페스트에서 해당 활동으로 설정 한 테마에 android : background를 설정해야합니다. 그렇게하지 않으면 (올바르게 구현 한 경우) 약 0.5-2 초 동안 흰 화면이 나타나고 스플래시 화면 애니메이션이 실행될 때 투명하게 바뀝니다.

+0

감사합니다. 문제가있는 곳을 찾아보기 시작합니다. –