大家好,我是 Vic
,今天给大家带来Android-如何显示版本号并制作3秒跳转页
的概述,希望你们喜欢
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@drawable/launch_bg">
<TextView
android:id="@+id/tv_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="@android:color/white"
android:textSize="14sp"/>
<RelativeLayout>
public class SplashActivity extends AppCompatActivity{
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
textView = findViewById(R.id.tv_version);
try{
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(),0);
textView.setText("version:"+info.versionName);
}catch(PackageManger.NameNotFoundException e){
e.printStackTrace();
}
Timer timer = new Timer();
TimerTask timerTask = new TimeTask(){
@Override
public void run(){
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
SplashActivity.this.finish();
}
};
timer.schedule(timerTask,3000);
}
}
Android
&Java
知识点,有兴趣可以继续关注