如图,点击跳过时,闪屏不再进行,将直接跳到主界面。
(1)SplanshScreen文件
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.support.annotation.Nullable; import android.view.View; import android.widget.Button; /** * Created by lenovo on 2018/4/16. */ public class SplanshScreen extends Activity { public Button bt_tg; private Handler handler; private Runnable runnable; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splan_activity); bt_tg=(Button) findViewById(R.id.tiaoguo); /** * 正常情况下不点击跳过 */ handler=new Handler(); handler.postDelayed(runnable= new Runnable() { @Override public void run() { //从闪屏界面跳转到首界面 Intent intent=new Intent(SplanshScreen.this,MainActivity.class); startActivity(intent); finish(); } },5000);//延迟5S后发送handler信息 /** * 点击跳过 */ bt_tg.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //从闪屏界面跳转到首界面 Intent intent=new Intent(SplanshScreen.this,MainActivity.class); startActivity(intent); finish(); if(runnable!=null){ handler.removeCallbacks(runnable); } } }); } }
(2)splan_activity。xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff"> <Button android:id="@+id/tiaoguo" android:layout_width="60dp" android:layout_height="40dp" android:textColor="#fff" android:textSize="15sp" android:background="#ADADAD" android:text="跳过" android:layout_alignParentRight="true" android:layout_marginRight="20dp" android:layout_marginTop="20dp"/> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@mipmap/icon_welcome" android:layout_alignParentBottom="true"/> </RelativeLayout>