显示操作栏,当用户在Android的一段时间内不进行交互时间内、操作、用户、Android

2023-09-12 03:30:51 作者:^我会哭,但我不会输〆

喜在我的Andr​​oid应用程序,我想隐藏用户交互操作栏,并再次显示它时,用户已经停止了一段时间的交互。现在,我已经有$ C $下隐藏操作栏:

Hi in my android app I would like to hide the action bar on user interaction and show it again when the user has stopped interacting for some time. Now I already have the code for hiding the action bar:

    mViewPager.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            getActionBar().hide();
            return false;
        }
    });

我只是增加了一个onTouchListener我的主要观点

I simply added an onTouchListener to my main view

但我不知道如何实施 getActionBar.show(); 方法。如何才能知道是否该用户已被不适合的互动,让我们说,2秒钟,从而实施 getActionBar()显示();?

But I do not know how to implement the getActionBar.show(); method. How do i find out whether the user has been not interacting for, let's say, 2 seconds and thus implement getActionBar().show();?

在此先感谢...

编辑:

    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
        SystemClock.sleep(3000);

        if (isCancelled()) {
            break;
        }
        return null;
    }

这code是给一个错误。 突破只能内部循环或开关使用。如何实现onCancelled()

This code is giving an error. break can only be used inside loop or switch. How to implement onCancelled()

推荐答案

最终你必须跟踪用户交互。 看看这篇文章: tracking-user-idle-time-within-the-app-in-android

ultimately you have to track the user interactions. have a look at this post : tracking-user-idle-time-within-the-app-in-android

使用这个概念,你可以跟踪时间和保存在preference。

By using this concept you can track the time and save in preference.

现在剩余的逻辑只用于显示动作条,如果用户不活跃一段时间间隔(假设2秒)。

Now remaining logic is only for showing the actionbar if user is not active for some time interval (suppose 2seconds).

对于这一点,你可以创建一个活动其中内定期(你的情况,在每一个2秒)通过调用检查最后的用户交互时间 getElapsed() method.if getElapsed()大于所需的时间(2秒)。然后显示动作条使用 getActionBar()。显示()方法。

For that, You can create a Thread inside your Activity which periodically (in your case,at every 2seconds) checks last user-interaction time by calling getElapsed() method.if getElapsed() is greater than your desired time(2seconds).then show actionbar using getActionBar().show() method.