How to make EditText not editable through XML in Android?

后端 未结 27 1828
梦谈多话
梦谈多话 2020-11-28 17:35

Can anyone tell me how to make an EditText not editable via XML? I tried setting android:editable to false, but

  1. it is de
27条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 18:09

    When I want an activity to not focus on the EditText and also not show keyboard when clicked, this is what worked for me.

    Adding attributes to the main layout

    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    

    and then the EditText field

    android:focusable="false"
    android:focusableInTouchMode="false"
    

    Here is an example:

    
    
    
        
    
    
    

提交回复
热议问题