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

7cbf955bc6ae44a509fbdda7b7b7997d.png

我想隐藏EditText的下划线并以white颜色显示光标。 我在EditText(从这里)使用透明背景也使用背景作为@null。 它隐藏了EditText的下划线并隐藏了光标。 但是......对于计算器App游标不应该被隐藏。

请给我一种隐藏EditText下划线的方法,并显示EditText的白色光标。

edittext.setBackground(null)

将背景drawable设置为透明,并将android:textCursorDrawable设置为null,使光标颜色始终为文本颜色。 例如:

android:id="@+id/editTextInput"

android:layout_width="match_parent"

android:layout_height="wrap_content"

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

android:textCursorDrawable="@null"/>

将背景drawable设置为透明,并设置您选择的Text Cursor drawable。 例如:

android:id="@+id/remarkEditText"

android:layout_width="match_parent"

android:layout_height="wrap_content"

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

android:textCursorDrawable="@drawable/white"/>

谢谢你,先生。 有用! 我刚刚创建了一个自定义光标,如: shape>

@HasanAbdullah非常欢迎你!

backgroundTint为我工作而不是背景。

通过Progamatically,您可以将EditText背景过滤器设置为此。 这会将其设置为清晰的背景颜色。

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

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

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

对于游标,您应该通过XML添加textCursorDrawable和cursorVisible。

请在EditText中添加一个:=

android:id="@+id/youId"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#00000000"

/>

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐