Disable EditText editability and focus (like TextView)

后端 未结 7 1383
说谎
说谎 2021-01-02 03:49

Is there a way to make EditText behaviors like TextView in Android (XML is prefered)? I have tried the following:

 android:editable         


        
7条回答
  •  青春惊慌失措
    2021-01-02 04:21

    EditText and TextView are quite similar. The only difference I see hard-coded into EditText.java is to set the editable default to true, which you've set manually. Other than that, the EditText style is:

    
    

    and TextView is:

    
    

    My guess is that @android:drawable/edit_text is the source of the orange box. Indeed, it contains:

    
    

    The simplest way might be to set its background to the default one:

    android:background="@android:drawable/textfield_default"

提交回复
热议问题