EditText: How to show cursor and hide underline at a time?

只谈情不闲聊 提交于 2019-12-24 10:39:49

问题


I'm developing an Calculator App. I wanna achieve the UI as like as Android default Calculator App. Please check my App's screenshot.

I want to hide the underline of EditText and show the cursor in white color. I used transparent background at EditText (from here) also used background as @null. It hides EditText's underline and also hide the cursor. BUT... for calculator App cursor should not be hidden.

Please give me a way to hide underline of EditText and show the EditText's cursor of white color.


回答1:


Set the background drawable as transparent and set the Text Cursor drawable of your choice. For Example:

<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:


Set the background drawable as transparent and set the android:textCursorDrawable null so the cursor color always text color. For Example:

<EditText
    android:id="@+id/editTextInput"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:textCursorDrawable="@null"/>



回答3:


please add one more thing in your EditText :=

<EditText
                android:id="@+id/youId"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#00000000"
                />



回答4:


Progamatically you could set the EditText background filter into this. This would set it into a clear background color.

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

Or via XML you can do this, but this would only work for Android API 21 +, your best option is the color filter.

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

For the cursor, you should add textCursorDrawable with cursorVisible via XML.



来源:https://stackoverflow.com/questions/49461990/edittext-how-to-show-cursor-and-hide-underline-at-a-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!