团队冲刺第九天--校园百晓生(STDeverything)

摘要:今天添加了启动页的内容,主要是3秒后自动跳转,封面海报等设置。

代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".login.Splash">

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/fengmian" />

    <TextView
        android:id="@+id/splash_tip_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:alpha="0.6"
        android:background="@drawable/splash_text_tip_style"
        android:gravity="center"
        android:textColor="#ffffff"
        android:textSize="18sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
layout
package com.lh.std_everything.login;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.lh.std_everything.R;

public class Splash extends AppCompatActivity {

    private TextView tv;
    private boolean flag=false;
    private int exitNum=3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_splash);
        tv=findViewById(R.id.splash_tip_text);

        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                while (!flag){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            tv.setText(String.valueOf(exitNum)+"秒后跳转");
                        }
                    });
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    exitNum--;
                    if(exitNum<0)
                        flag=true;
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        startActivity(new Intent(Splash.this,Login.class));
                    }
                });
            }
        });
        thread.start();
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                flag=true;   //改变退出标志
            }
        });
    }

}
splash

 界面展示:

 

posted @ 2020-04-23 19:11  土豆面包  阅读(134)  评论(0编辑  收藏  举报