Android 开发指南 翻译3:User Interface: Input Events
来源:互联网 发布:阿里云最便宜的主机 编辑:程序博客网 时间:2024/06/06 03:42
Android 开发指南 翻译3:User Interface:Input Events
These methods are called by the Android framework when the respective action occurs on that object.
Event Listeners
An event listener is an interface in theView
class that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI.事件监听器是View的一个接口,包含一个回调方法。当注册了监听器的视图与用户进行交互时,这些回调方法将被Android调用。
View.onClickListeneronClick()View.OnLongClickListeneronLongClick()
View.OnFocusChangeListener
onFocusChange() View.OnKeyListener
.onKey() View.OnTouchListener
onTouch()View.OnCreateContextMenuListeneronCreateContextMenu()例子:// Create an anonymous implementation of OnClickListenerprivate OnClickListener mCorkyListener = new OnClickListener() { public void onClick(View v) { // do something when the button is clicked }};protected void onCreate(Bundle savedValues) { ... // Capture our button from layout Button button = (Button)findViewById(R.id.corky); // Register the onClick listener with the implementation above button.setOnClickListener(mCorkyListener); ...}
Remember that key events are always delivered to the View currently in focus.
key事件总是分配给当前获得光标的View。
Event Handlers
Touch Mode
For a touch-capable device, once the user touches the screen, the device will enter touch mode. From this point onward, only Views for whichisFocusableInTouchMode()
is true will be focusable, such as text editing widgets. Other Views that are touchable, like buttons, will not take focus when touched; they will simply fire their on-click listeners when pressed.
非触摸模式:显示获得焦点的控件,以告知用户当前的焦点。
触摸模式:只有部分控件获得焦点时,才显示给用户。
对与可触摸的设备,用户一旦触摸屏幕,就进入触摸模式。
Any time a user hits a directional key or scrolls with a trackball, the device will exit touch mode, and find a view to take focus. Now, the user may resume interacting with the user interface without touching the screen.
用户只要使用方向键或滚球,系统退出触摸模式。
Handling Focus
Views indicate their willingness to take focus through theisFocusable()
method. To change whether a View can take focus, callsetFocusable()
. When in touch mode, you may query whether a View allows focus with isFocusableInTouchMode()
. You can change this withsetFocusableInTouchMode()
.调用isFocusable()是否可以接收光标;setFocusable()设置;在xml中通过 android:focusable
设定。
- Android 开发指南 翻译3:User Interface: Input Events
- Android 开发指南 翻译 User Interface -- Dialogs
- Android 开发指南翻译开篇--User Interface -Styles and Themes
- Android 开发指南 翻译2 User Interface:XML Layouts
- Dev Guide/Framework Topics/User Interface/Input Events
- Android 开发指南 翻译 User Interfaces -- Action Bar
- [Android SDK 翻译] User Interface Guidelines
- API-user Interface翻译
- android -Input Events
- Android API Guides---Input Events
- Android - User Interface
- Android官方文档翻译 五 1.3Building a Simple User Interface
- Android SDK开发指南(翻译)系列:引言
- Android 开发指南 翻译4 Application Resources
- Android 开发指南 翻译6 Accessing Resources
- Android 开发指南以及翻译API等
- Input Events
- Android 用户界面---输入事件(Input Events)
- 分享SFTP简单的使用方法
- 实验4-2 逻辑表达式
- 某个操作挂起-避免安装SQL,Server时出现的“某个操作挂起”需要重启的提示
- LINUX主要目录及内容
- 8款最新流行的jquery插件
- Android 开发指南 翻译3:User Interface: Input Events
- 【Redis】Why is an Event Library needed at all?
- 用命令行删除指定文件夹下面的所有文件(如果里面没有子文件夹)
- C++ Dll 导出函数头文件
- 实验4-3 if结构的初步
- android 判断有没有和服务器连接上
- 实验4-4 if结构的分析
- slab alloc内存分配机制
- Struts2为应用指定多个配置文件和动态方法调用以及通配符的使用方法