Android:状态栏通知上的监听器 [英] Android: listener on the status bar notification
本文介绍了Android:状态栏通知上的监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
android:是否有办法在下拉状态栏时监听状态栏通知?
android:Is there a way to listen to the status bar notification when it is being pulled down?
推荐答案
1.要检测状态栏的更改:您可以注册一个侦听器,以获取有关系统UI可见性更改的通知
因此要在您的活动中注册侦听器:
So to register the listener in your activity:
// Detecting if the user swipe from the top down to the phone
// screen to show up the status bar (without showing the notification area)
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) {
// The system bars are visible.
} else {
// The system bars are NOT visible.
}
}
});
请查看文档中的更多信息
2.要检测用户是否拉下状态栏的通知区域,请执行以下操作:在您的活动中覆盖onWindowFocusChanged()
2. For detecting if the user pulls down the notification area of the status bar: override onWindowFocusChanged()
in your activity
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) { // hasFocus is true
// the user pushed the notification bar back to the top
Log.i("Tag", "Notification bar is pushed up");
} else { // hasFocus is false
// the user pulls down the notification bar
Log.i("Tag", "Notification bar is pulled down");
}
super.onWindowFocusChanged(hasFocus);
}
在 查看全文