gpt4 book ai didi

java - 闪屏跳过触摸事件

转载 作者:太空宇宙 更新时间:2023-11-04 11:06:25 24 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序,它有一个运行时间为 2500 毫秒的闪屏。我想添加用户触摸屏的功能并跳过此 Activity 。

我可以用一个按钮来实现,但为了相当客观,我只想添加一个屏幕触摸监听器(不知道如何。)

我的启动画面:

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>

最佳答案

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

关于java - 闪屏跳过触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46437808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com