gpt4 book ai didi

java - 如何运行启动画面,然后介绍 slider ,然后运行主要 Activity

转载 作者:行者123 更新时间:2023-11-30 02:04:14 25 4
gpt4 key购买 nike

我想运行诸如启动屏幕之类的 Activity ,然后是介绍 slider ,然后是主要 Activity 。但它运行启动画面,但在闪屏后不运行介绍 slider 。如何解决这个问题?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.introslider">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="info.androidhive.introslider.Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="info.androidhive.introslider.WelcomeActivity" />
<activity
android:name="info.androidhive.introslider.MainActivity"
android:label="@string/title_activity_welcome"
android:theme="@style/AppTheme.NoActionBar"/>
</application>
</manifest>

启动画面.java

package info.androidhive.introslider;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class Splashscreen extends Activity {
private static int SPLASH_TIMER = 1000;
@Override
protected void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(Splashscreen.this,MainActivity.class);
startActivity(i);
finish();
}
},SPLASH_TIMER);
}
}

最佳答案

SplashScreen.java这是您的第一个文件

    public class Splashscreen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);
new Timer().schedule(new TimerTask() {
@Override
public void run() {

Intent intent = new Intent(this, WelcomeActivity.class);
startActivity(intent);
finish();
}
}, 5000);

}
}

WelcomeActivity.java

   public class WelcomeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);
Button btn =findViewById(R.id.welcome_botton);

btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
});
}
}

WelcomeActivity.xml

<Button
android:id="@+id/welcome_botton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button" />

MainActivity.java

 public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);

// YOUR MAIN ACTIVITY LOGIC WRITE HERE
}
}

引用此层次结构并在 Manifest.xml 文件中注册所有 Activity 这些都是我创建的 Activity 供您引用。

关于java - 如何运行启动画面,然后介绍 slider ,然后运行主要 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51830042/

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