我的飞溅屏幕显示在2秒后,但我希望它也在屏幕触摸后,如我按下屏幕,我移动下一页,而不是等到计时器结束。有可能吗??
public class SplashActivity extends Activity {
    Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashfile);
                    handler=new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            startActivity(new Intent(getApplicationContext(),LoginActivity.class));
                            finish();
                        }
                    },2000);
            }
}发布于 2020-12-01 08:15:57
Tes是可能的,您可以在布局中添加一个触摸监听器,与两秒钟后会发生的事情相同,有些类似的事情
findViewById(R.id.myLayout).setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                startActivity(new Intent(getApplicationContext(),LoginActivity.class));
                            finish();
                return true;
            }
        });编辑:,如果布局没有接收到触摸事件,则可以在onCeate方法之外添加下一段代码:
@Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        startActivity(new Intent(getApplicationContext(),LoginActivity.class));
        finish();
        return super.dispatchTouchEvent(ev);
    }https://stackoverflow.com/questions/65086407
复制相似问题