• Android-如何显示版本号并制作3秒跳转页


    前言

    大家好,给大家带来Android-如何显示版本号并制作3秒跳转页的概述,希望你们喜欢

    软件技术人员,时代作者,从 Android 到全栈之路,我相信你也可以!阅读他的文章,会上瘾!You and me, we are family !

    创建布局文件

    <?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>
    

    创建一个版本Activity类

    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-如何显示版本号并制作3秒跳转页,如果您还有更好地理解,欢迎沟通
    • 定位:分享 Android&Java知识点,有兴趣可以继续关注
  • 相关阅读:
    ConcurrentHashMap
    Linux中如何开启8080端口供外界访问 和开启允许对外访问的端口8000
    CentOs 7 Linux系统下我的/etc/sysconfig/路径下无iptables文件
    CentOS7开启SSH服务
    Centos7下Samba服务器配置
    CentOS7(Linux)网络yum源配置
    Linux(Centos7)中配置Java环境变量
    SpringAOP-什么是面向切面编程?
    Swagger Demo
    自定义个Bean名称生成策略, 解决不同包下同名类问题/AnnotationBeanNameGenerator
  • 原文地址:https://www.cnblogs.com/dashucoding/p/9285627.html
Copyright © 2020-2023  润新知