我正在開發一個android應用程序,它有一個運行時間爲2500ms的Splash Screen。 我想爲用戶觸摸屏添加功能並跳過此活動。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;
}
});
}
}
我splashactivity佈局:
<?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>
好吧,那是邏輯,但是如何在代碼中? –
在splashactivity佈局中爲根RelativeLayout提供一個id,並通過finViewById()方法獲取根視圖,然後爲根視圖設置touch偵聽器。如果它對你有幫助,請註冊。 – namezhouyu
我做到了,但onTouchListener根本沒有owrk,更新代碼修復... –