Make EditText behave as a TextView in code

后端 未结 8 2244
暗喜
暗喜 2020-12-29 13:39

How to make an EditText look like a TextView that is done in Java but not in XML..

I have seen how to do it using xml file like

style=\"@android:styl         


        
相关标签:
8条回答
  • 2020-12-29 14:16

    This was all I needed to create the effect.

    In code:

    ET.setFocusable(false);
    

    And in layout:

    android:background="@android:color/transparent"
    

    Setting the background in the layout completely removes the under bar, as apposed to just hiding it in code.

    Make it editable again with:

    ET.setFocusableInTouchMode(true);
    
    0 讨论(0)
  • 2020-12-29 14:20
    EditText Et; // initialize your edittext//
    
    Et.setCursorVisible(false);
    Et.setLongClickable(false);
    Et.setClickable(false);
    Et.setFocusable(false);
    Et.setSelected(false);
    Et.setKeyListener(null);
    Et.setBackgroundResource(android.R.color.transparent);
    

    And you'll never see it like an EditText again.

    0 讨论(0)
提交回复
热议问题