Edittext在xml文件中设置android:focusable=“false”之后,edittext再次获得焦点。
2015-01-26 20:58
459 查看
在xml文件中,edittext这个控件设置了,android:focusable=“false”,
在代码中edittext.setfocusable(true),edittext这个控件仍然无法点击,百度之后,得到的结果是:
一定要按一下这个顺序写,重新使edittext获取焦点:
edittext.setFocusable(true);
edittext.setFocusableInTouchMode(true);
edittext.requestFocus();
edittext.requestFocusFromTouch();
这是为什么呢?
查阅API:
setFocusable(boolean):
Set whether this view can receive the focus. Setting this to false will also ensure that this view is not focusable in touch mode.
//--设置edittext是否可以获得焦点
setFocusableInTouchMode(boolean):
Set whether this view can receive focus while in touch mode. Setting this to true will also ensure that this view is focusable.
//--设置edittext在touch模式下是否可以获得焦点
requestFocus():
Call this to try to give focus to a specific view or to one of its descendants. A view will not actually take focus if it is not focusable (
in touch mode (
//--调用这个给指定的view或者它的子view焦点。如果这个view在isFocusable()方法下返回false,或者isFocusableInTouchMode()方法下返回false,这个view不会真正获得焦点
requestFocusFromTouch():
Call this to try to give focus to a specific view or to one of its descendants. This is a special variant of
//--调用这个给指定的view或者它的子view焦点。这个特别的变异于(?)requestFocus()的方法会让在这个view被touch时,给view焦点。
以上。
在代码中edittext.setfocusable(true),edittext这个控件仍然无法点击,百度之后,得到的结果是:
一定要按一下这个顺序写,重新使edittext获取焦点:
edittext.setFocusable(true);
edittext.setFocusableInTouchMode(true);
edittext.requestFocus();
edittext.requestFocusFromTouch();
这是为什么呢?
查阅API:
setFocusable(boolean):
Set whether this view can receive the focus. Setting this to false will also ensure that this view is not focusable in touch mode.
//--设置edittext是否可以获得焦点
setFocusableInTouchMode(boolean):
Set whether this view can receive focus while in touch mode. Setting this to true will also ensure that this view is focusable.
//--设置edittext在touch模式下是否可以获得焦点
requestFocus():
Call this to try to give focus to a specific view or to one of its descendants. A view will not actually take focus if it is not focusable (
isFocusable()returns false), or if it is focusable and it is not focusable
in touch mode (
isFocusableInTouchMode()) while the device is in touch mode.
//--调用这个给指定的view或者它的子view焦点。如果这个view在isFocusable()方法下返回false,或者isFocusableInTouchMode()方法下返回false,这个view不会真正获得焦点
requestFocusFromTouch():
Call this to try to give focus to a specific view or to one of its descendants. This is a special variant of
requestFocus()that will allow views that are not focuable in touch mode to request focus when they are touched.
//--调用这个给指定的view或者它的子view焦点。这个特别的变异于(?)requestFocus()的方法会让在这个view被touch时,给view焦点。
以上。
相关文章推荐
- Android启动Activity之后阻止EditText自动获得焦点
- 解决Android EditText获得焦点之后无法弹出软键盘输入法
- Android EditText设置默认不弹出软键盘,点击EditText外部隐藏软键盘,EditText获取焦点时隐藏hint
- Android中其中一个Activity可以对另一个Activity的xml文件中的EditText设置进行设置吗?
- android 设置 EditTextView不自动获得焦点
- android EditText输入框获得焦点时,边框变为深色
- android xml布局文件中EditText的属性详解
- Android中EditText点击获得焦点后无法显示输入法键盘
- edittext设置获得焦点时的边框颜色
- android EditText 默认情况下不获取焦点(不弹出输入法)+点击EditText时,不弹出键
- [Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- [Android]去除EditText自动获得的焦点,解决软键盘弹出问题
- Android中设置EditText获得焦点时不弹出软键盘
- Android - 小功能 - EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- edittext设置获得焦点时的边框颜色
- 【EditText】Android设置EditText不可编辑
- Android中使EditText失去焦点,edittext禁止弹出键盘
- Android--Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- [Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- Android EditText获得焦点时边框颜色改变