Tap outside edittext to lose focus

后端 未结 9 1683
萌比男神i
萌比男神i 2020-12-24 02:02

I just want when click outside the \"edittext\" to automatically lose focus and hide keyboard. At the moment, if I click on the \"edittext\" it focuses but i need to hit the

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 02:29

    @woodshy has the answer for hiding the keyboard, but maybe putting the code in onClick is not as good as putting it in onFocusChanged. As for forcing it to lose focus, you need to set the object you want to transfer the focus to, in its XML file:

    android:focusable="true"
    android:focusableInTouchMode ="true"
    

提交回复
热议问题