2012-07-02 232 views
0

我相信我的代碼已正確設置,但是當我嘗試調試它時,它從閃屏切換到黑屏。我知道我正確導入了佈局,但它仍然變黑。過渡到黑色屏幕

這是初始屏幕

package com.example.equate.jones; 



import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.support.v4.app.NavUtils; 

public class EJ_Splash extends Activity { 

    protected boolean _active = true; 
    protected int _splashTime = 3000; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_ej__splash); 

     // thread for displaying the SplashScreen 
     Thread splashTread = new Thread() { 
      @Override 
      public void run() { 
       try { 
         synchronized(this){ 
          wait(4000); 
         } 

        } 
       catch(InterruptedException e) { 
        // do nothing 
       } { 

        finish(); 

        Intent i = new Intent(getApplicationContext(),EJ_Board.class); 
        startActivity(i); 
       } 
      } 
     }; 
     splashTread.start(); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.activity_ej__splash, menu); 
     return true; 
    } 


} 

代碼這是它應該轉換到屏幕的代碼。

package com.example.equate.jones; 

import android.app.Activity; 
import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ImageView; 

public class EJ_Board extends Activity { 

    private ImageView button1; 
    final MediaPlayer mp = MediaPlayer.create(this, R.raw.warm); 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.ej_board); 


     button1=(ImageView)findViewById(R.id.imageView1); 

     button1.setOnClickListener(new View.OnClickListener() 
     { 
      public void onClick(View view) 
      { 

       mp.start(); 
      } 
     }); 
    } 

} 

這是EJ_Board

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 
+0

Can你發佈了EJ_Board的XML代碼? – BlackHatSamurai

+0

好吧我更新了它。 – todaroa

+0

我有點困惑,爲什麼你的屏幕上有一個菜單inflater。您的啓動畫面應該在沒有任何菜單的情況下轉換到您的下一頁。我認爲這與您的問題沒有任何關係,但無論如何,仍然需要考慮。 :) – BlackHatSamurai

回答

1

的XML我覺得你的問題是與ImageView的。您需要將圖像添加到您的可繪製文件夾中,然後將您的android:src="@drawable/ic_launcher"更改爲您保存的圖像的名稱。這會給你你的按鈕所需的圖像。希望幫助

編輯:

爲了您的閃屏,嘗試這樣的事情:

public class SplashActivity extends Activity { 
    private long splashDelay = 5000; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 

     TimerTask task = new TimerTask() 
     { 

      @Override 
      public void run() { 
       finish(); 
       Intent homeIntent = new Intent().setClass(SplashActivity.this, HomeActivity.class); 
       startActivity(homeIntent); 

      } 

     }; 

     Timer timer = new Timer(); 
     timer.schedule(task, splashDelay); 

    } 
} 

然後在你家的活動,您可以設置菜單:

public class HomeActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

    } 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     MenuInflater inflater = getMenuInflater(); 
     inflater.inflate(R.layout.menu, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle item selection 
     switch (item.getItemId()) { 
      case R.id.locationButton: 
       Intent locationIntent = new Intent(this, LocationActivity.class); 
       startActivity(locationIntent); 
       return true; 
      case R.id.diningButton: 
       Intent diningIntent = new Intent(this, DiningActivity.class); 
       startActivity(diningIntent); 
       return true; 

      case R.id.topXXVButton: 
       Intent topIntent = new Intent(this, DiningActivity.class); 
       startActivity(topIntent); 
       return true; 

      default: 
       return super.onOptionsItemSelected(item); 
     } 
    } 
} 

試試這個:

public class SplashActivity extends Activity { 
    private long splashDelay = 5000; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 

     TimerTask task = new TimerTask() 
     { 

      @Override 
      public void run() { 
       finish(); 
       Intent mainIntent = new Intent().setClass(EJ_Splash.this, EJ_Board.class); 
       startActivity(mainIntent); 

      } 

     }; 

     Timer timer = new Timer(); 
     timer.schedule(task, splashDelay); 

    } 
} 
+0

轉換沒有任何錯誤,我認爲它開始活動錯誤 – todaroa

+0

您是否將活動添加到Android清單中?如果你願意,發佈你的Android清單。 – BlackHatSamurai

+0

我添加了一些可能對您有幫助的代碼。請讓我知道這對你有沒有用。 – BlackHatSamurai