android xml 焦点,Edittext在xml文件中设置android:focusable=“false”之后,edittext再次获得焦点。...

在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 (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焦点。

以上。

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

小编个人微信号 jb51ccc

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值