简体   繁体   中英

SplashScreen skip on Touch event

I'm developing an android app, it has a Splash Screen that runs for 2500ms. I want to add the functionality for a User touch screen and skip this Activity.

I could made it with a button, but for pretty objective I just want to add a screen touch listener (Don't know how.)

My SplashScreen:

public class Splash extends Activity {

// Splash screen timer
private static int SPLASH_TIME_OUT = 2500;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splashactivity);

    /*
     * Showing splash screen with a timer. This will be useful when you
     * want to show case your app logo / company
     */
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            startActivity(new Intent(Splash.this, MainActivity.class));
            finish();
        }
    }, SPLASH_TIME_OUT);

//Skip this intro
        RelativeLayout root_layout = (RelativeLayout) findViewById(R.id.root_splash);
        root_layout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                startActivity(new Intent(Splash.this, MainActivity.class));
                finish();
                return true;
            }
        });
}
}

My splashactivity layout:

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_splash"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splash_screen">

</RelativeLayout>

Delete the splash screen. That's so 2007.

Add onTouchListener on Splash screen layout and call your class on the event. Hope it will work for you

Thanks..

在R.layout.splashactivity中添加一个名为ll_root的全屏视图,然后在Splash Activity中使用findViewById和setOnTouchListener作为ll_root。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM