温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

android 启动延迟加载画面

发布时间:2020-07-02 00:34:36 来源:网络 阅读:1294 作者:liang3391 栏目:移动开发
LoginActivity
package com.xkhouse.erm.erm;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
/* public class LoginActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }
}  */
public class LoginActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*
         * 设置隐藏标题栏
         */
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_login);
    }
}
/* public class SplashActivity extends Activity {
    private final int SPLASH_DISPLAY_LENGHT = 1000; //延迟一秒
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jiazai);
        new Handler().postDelayed(new Runnable() {
            // 为了减少代码使用匿名Handler创建一个延时的调用
            public void run() {
                Intent i = new Intent(SplashActivity.this, LoginActivity.class);
                // 通过Intent打开最终真正的主界面Main这个Activity
                SplashActivity.this.startActivity(i); // 启动Main界面
                SplashActivity.this.finish(); // 关闭自己这个开场屏
            }
        }, SPLASH_DISPLAY_LENGHT);
    }
} */

SplashActivity

package com.xkhouse.erm.erm;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
/*public class SplashActivity extends Activity {
    private final int SPLASH_DISPLAY_LENGHT = 6000; // 延迟六秒
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        new Handler().postDelayed(new Runnable() {
            public void run() {
                Intent mainIntent = new Intent(SplashActivity.this,
                        LoginActivity.class);
                SplashActivity.this.startActivity(mainIntent);
                SplashActivity.this.finish();
            }
        }, SPLASH_DISPLAY_LENGHT);
    }
} */
public class SplashActivity extends Activity {
    final private int SPLASH_TIME = 1000;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*
         * 设置全屏
         */
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        /*
         * 设置隐藏标题栏
         */
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        /*
         * 2秒后跳转到主界面
         */
        new Handler().postDelayed(new Runnable() {
            public void run() {
                launchMainActivity();
            }
        }, SPLASH_TIME);
        setContentView(R.layout.activity_splash);
    }
    /*
     * 利用Intent切换到主Activity
     */
    private void launchMainActivity() {
        /*
     * 创建一个intent,从当前Activity指向要跳转的Activity
     */
        Intent intent = new Intent(this, LoginActivity.class);
    /*
     * 启动目标Activity
     */
        startActivity(intent);
    /*
     * 启动画面只需要程序开始时显示一次,显示完后即可退出
     */
        finish();
    }
}


layout目录下
activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
    <ImageView android:layout_height="fill_parent" android:layout_width="fill_parent" android:scaleType="fitCenter" android:src="@drawable/splash"></ImageView>
</LinearLayout>
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xkhouse.erm.erm">
    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <activity
            android:name="com.xkhouse.erm.erm.SplashActivity"
            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"></activity>
    </application>
</manifest>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI