这是显示的效果:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NUswCSZ7-1689046670792)(//img-blog.csdn.net/20180507212022876?watermark/2/text/Ly9ibG9nLmNzZG4ubmV0L3RpdGxlNzE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)]
想实现这个功能的话,看下面教你怎么做
第一步
随便新建一个文件,(建议先在桌面建),文件命名为
Init_Activity.java
然后复制以下内容(先不用关心内容先按着我做)
package com.title71.ywl.demo5;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class Init_Activity extends Activity{
private TextView init_text_number;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.init_activity);
init_text_number = (TextView)findViewById(R.id.init_text_number);
timer_start();
}
private int timer_flag =3;
private void timer_start()
{
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
Message msg =new Message();
msg.what = 1;
msg.obj = timer_flag;
handler.sendMessage(msg);
timer_flag--;
if(timer_flag < 0)
{
timer_flag = 3;
timer.cancel();
Intent intent = new Intent(Init_Activity.this,MainActivity.class);
startActivity(intent);
}
}
}, 3, 1000);
}
private Handler handler =new Handler()
{
public void handleMessage(Message msg)
{
if(msg.what == 1)
{
init_text_number.setText(""+msg.obj);
}
}
};
}
第二步
再建一个文件init_activity.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"
android:background="@drawable/init"
>
<TextView
android:id="@+id/init_text_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="3"
android:textColor="#FFFFFFFF"
android:textSize="15sp" />
</LinearLayout>
第三步
找一个图片,命名为init
比如这个图片
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OHVnQDsF-1689046670793)(//img-blog.csdn.net/20180507213242317?watermark/2/text/Ly9ibG9nLmNzZG4ubmV0L3RpdGxlNzE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)]
最后一步
修改AndroidManifest.xml
Androidstudio的这个文件在manifests中
千万注意
修改我注释的内容
修改我注释的内容
修改我注释的内容
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.title71.ywl.demo5">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--先加载全屏的页面--> <activity android:name=".Init_Activity" android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"><!--先加载全屏的页面-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--再加载自己的主页面--><activity android:name=".MainActivity"> </activity><!--再加载自己的主页面-->
</application>
</manifest>
最后复制拷贝文件到对应的工程目录(studio提示的话默认会帮你修改内容的)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-qYrpnsAO-1689046670793)(//img-blog.csdn.net/20180507214512693?watermark/2/text/Ly9ibG9nLmNzZG4ubmV0L3RpdGxlNzE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)]