gpt4 book ai didi

java - 过渡到黑屏

转载 作者:行者123 更新时间:2023-12-01 15:18:31 25 4
gpt4 key购买 nike

我相信我的代码设置正确,但是当我尝试调试它时,它从启动屏幕转换后直接进入黑屏。我知道我正确导入了布局,但它仍然变黑。

这是启动屏幕的代码

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>

最佳答案

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

}
}

然后在您的家庭 Activity 中您可以设置菜单:

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

}
}

关于java - 过渡到黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11302304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com