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

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

1 回答 1

1

我认为您的问题出在 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);

    }
}
于 2012-07-02T23:27:11.667 回答