简体   繁体   English

确定Android何时完成UI更新

[英]Determine when Android has finished updating UI

I'm using ActivityInstrumentationTestCase2 to test my UI. 我正在使用ActivityInstrumentationTestCase2来测试我的UI。 My tests will change some value that will appear on the screen. 我的测试将更改一些出现在屏幕上的值。 However, after setting the value, I then test the screen by taking a snapshot image, run a checksum on the bitmap and compare the checksum value to the expected value. 但是,设置完该值之后,我将通过拍摄快照图像来测试屏幕,在位图上运行校验和,并将校验和的值与期望值进行比较。 But after setting the UI value, Android has not completed its updating of the UI. 但是在设置UI值后,Android尚未完成其UI的更新。 The only solution I've figured out is to use a delay to wait for several seconds although this is not desirable as it has unnecessary waiting time that adds up with enough tests. 我发现的唯一解决方案是使用延迟等待几秒钟,尽管这是不希望的,因为它具有不必要的等待时间,并且需要进行足够的测试。 Is there some way of knowing when Android has actually finished updating my UI? 有什么方法可以知道Android何时实际完成了UI的更新?

Doing some more research I came across this. 做更多的研究,我发现了这一点。 Have yet to try it: 尚未尝试:

To get notified of system UI visibility changes, register an View.OnSystemUiVisibilityChangeListener to your view. 要获取有关系统UI可见性更改的通知,请在您的视图中注册View.OnSystemUiVisibilityChangeListener。 This is typically the view you are using to control the navigation visibility. 通常,这是您用来控制导航可见性的视图。

For example, you could add this code to your activity's onCreate() method: 例如,您可以将此代码添加到活动的onCreate()方法中:

View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
        (new View.OnSystemUiVisibilityChangeListener() {
    @Override
    public void onSystemUiVisibilityChange(int visibility) {
        // Note that system bars will only be "visible" if none of the
        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
            // TODO: The system bars are visible. Make any desired
            // adjustments to your UI, such as showing the action bar or
            // other navigational controls.
        } else {
            // TODO: The system bars are NOT visible. Make any desired
            // adjustments to your UI, such as hiding the action bar or
            // other navigational controls.
        }
    }
});

http://developer.android.com/training/system-ui/visibility.html http://developer.android.com/training/system-ui/visibility.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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