代码之家  ›  专栏  ›  技术社区  ›  Hasan Abdullah

EditText:如何一次显示光标和隐藏下划线?

  •  2
  • Hasan Abdullah  · 技术社区  · 7 年前

    我正在开发一个计算器应用程序。我想实现像Android默认计算器应用程序一样的UI。请检查我的应用程序的屏幕截图。

    enter image description here

    我想隐藏的下划线 EditText 并在中显示光标 white 颜色我在EditText中使用了透明背景(来自 here )也将背景用作 @null 。它隐藏EditText的下划线,也隐藏光标。但是。。。对于计算器应用程序,不应隐藏光标。

    请给我一个隐藏下划线的方法 编辑文本 并以白色显示EditText的光标。

    4 回复  |  直到 7 年前
        1
  •  2
  •   Kishan    7 年前

    将背景可绘制设置为透明,并将文本光标设置为可绘制。例如:

    <EditText
                    android:id="@+id/remarkEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    android:textCursorDrawable="@drawable/white"/>
    
        2
  •  2
  •   Sadda Hussain    7 年前

    将背景可绘制设置为透明,并将android:textCursorDrawable设置为null,以便光标颜色始终为文本颜色。例如:

    <EditText
        android:id="@+id/editTextInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:textCursorDrawable="@null"/>
    
        3
  •  0
  •   Abhinav Gupta Eduardo Oliveira    7 年前

    请在你的简历中再加一件事 EditText :=

    <EditText
                    android:id="@+id/youId"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#00000000"
                    />
    
        4
  •  0
  •   Jojo Narte    7 年前

    从程序上来说,您可以设置 EditText 将背景筛选到此中。这会将其设置为清晰的背景色。

    editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
    

    或者通过XML可以做到这一点,但这只适用于Android API 21+,您最好的选择是颜色过滤器。

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

    对于光标,应添加 textCursorDrawable 具有 cursorVisible 通过XML。