How to hide underbar in EditText

后端 未结 25 1766
温柔的废话
温柔的废话 2020-11-28 00:52

How can I hide the EditText underbar (the prompt line with little serifs at the ends)?

There might be a better way to do what I want: I have a layout with an EditTe

相关标签:
25条回答
  • 2020-11-28 01:27

    Set background to null

    android:background="@null" in your xml 
    
    0 讨论(0)
  • 2020-11-28 01:28

    if you are using background then you must use this tag

    android:testCursorDrawable="@null" 
    
    0 讨论(0)
  • 2020-11-28 01:30
    android:background="@android:color/transparent"
    

    Or

    android:background="@null"
    
    0 讨论(0)
  • 2020-11-28 01:31

    Simply Use This

     editText.setBackgroundColor(Color.TRANSPARENT);
    
    0 讨论(0)
  • 2020-11-28 01:31

    If you are using the EditText inside TextInputLayout use app:boxBackgroundMode="none" as following:

    <com.google.android.material.textfield.TextInputLayout
        app:boxBackgroundMode="none"
        ...
        >
    
        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    </com.google.android.material.textfield.TextInputLayout>
    
    0 讨论(0)
  • 2020-11-28 01:32

    You can also define a STYLE for your editText so you can regroup all properties in common. It is very powerful if you have to multiple edit text that need to has the behaviour

    Put the code in res/values/styles.xml

    <style name="MyEditTextStyle" parent="@android:style/TextAppearance.Widget.EditText">
        <item name="android:background">@color/transparence</item> //NO UNDERBAR
        <item name="android:maxLines">1</item>
        <item name="android:height">28dp</item> //COMMON HEIGHT
    </style>
    

    After that you just need to call it in your editText

    <EditText
        android:id="@+id/edit1"
        style="@style/MyEditTextStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    
    <EditText
        android:id="@+id/edit2"
        style="@style/MyEditTextStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    
    0 讨论(0)
提交回复
热议问题