How to handle touch outside the view in Android?(如何在Android中处理视图外的触摸?)
问题描述
我找到了 "撤消栏" 用于 Android 的 Gmail 应用程序.UndoBar"基本上是一个显示在布局顶部的视图.
I've found implementation of "Undo Bar" used in Gmail application for Android. "UndoBar" is basically a View that is displayed on top of the layout.
不幸的是,它不完整 - 它没有通过触摸栏外的屏幕来关闭栏的功能.
Unfortunately it's not complete - it has no functionality of dismissing bar by touching screen outside the bar.
我已经实现了 FrameLayout
,它覆盖了 onInterceptTouchEvent
来处理 bar 的关闭,但触摸 Action Bar 什么也没做.
I've implemented FrameLayout
that overrides onInterceptTouchEvent
to handle bar dismissing but touching Action Bar does nothing.
有什么方法可以处理来自操作栏的此类事件?
Is there any way to handle such events from Action Bar?
下面有一个带有UndoBar"的图像.我想要在红点表示的操作栏中处理触摸.
Below there is an Image with "UndoBar"shown. What I want to achieve to handle touch in Action bar represented by red dot.
推荐答案
尝试重写你的activity的dispatchTouchEvent.
Try to override dispatchTouchEvent of your activity.
dispatchTouchEvent(MotionEvent event){
int x= event.getRawX();
int y= event.getRawY();
if(/*check bounds of your view*/){
// set your views visiblity to gone or what you want.
}
//for prevent consuming the event.
return super().dispatchTouchEvent(event);
}
更新
dispatchTouchEvent(MotionEvent event){
int x= event.getRawX();
int y= event.getRawY();
return super().dispatchTouchEvent(event)||[YourView].onTouch(event);
}
这篇关于如何在Android中处理视图外的触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在Android中处理视图外的触摸?


- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01