实现安卓启动页设置

1、新建一个AndroidActivity,会同时新建一个.xml

名称命名为StartActivity.java

2、其中StartActivity.java的内容为:

package com.example.jj;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
public class StartActivity extends Activity {

//延迟3秒 
    private static final long SPLASH_DELAY_MILLIS = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_start);
// 使用Handler的postDelayed方法,3秒后执行跳转到MainActivity 
        new Handler().postDelayed(new Runnable() {
            public void run() {
                goHome();
                
            }
        }, SPLASH_DELAY_MILLIS);
    }


    private void goHome() {
    Intent intent=null; 
         intent = new Intent(StartActivity.this, MainActivity.class);
        StartActivity.this.startActivity(intent);
        StartActivity.this.finish();
    }
}

3、对应xml的文件内容为:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >


 <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/startbg"
        
 
        android:scaleType="fitCenter" />


</RelativeLayout>

4、在/test/AndroidManifest.xml内容进行修改,在MainActivity前面,即是第一个界面的前面进行添加:

<activity
            android:name=".StartActivity"
            android:configChanges="keyboardHidden"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

5、需要注意的是:

(1)如果粘贴过去出现R文件报错时,不能直接对R文件进行修改,需要刷新一下,然后选择Project-》Clean一下,重新加载一下R文件。

(2)如果需要修改启动页图片时,记得不要出现中文符号,包括名称中“-”一定改为“_”英文的,不然报错。

(3)修改/test/AndroidManifest.xml记得放在第一个页面的前面。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

洋葱ycy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值