[英]How to underline an EditText
我在 AndroidStudio 中在 EditText 下划線時遇到了一些問題。
這就是我要找的(這只是一張照片,不是我的真實文字):
但我真的不知道有什么財產可以做到這一點。
我現在的代碼非常簡單。 只是“正常”的一個:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_margin="16dp"
android:id="@+id/tx_titulo"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="@string/pt_titulo"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:allowUndo="true"
/>
我不想只在文本下划線(在本例中為“Título”),而是整個 PlainText
有人知道嗎? 問候。
這是默認設置,但請嘗試檢查您的樣式。 也許有一種樣式會覆蓋整個應用程序中的樣式。 如果有,只需將其刪除
要以編程方式執行此操作,您可以在這篇文章中找到答案。
要設置下划線顏色:
editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
要刪除下划線顏色:
editText.getBackground().clearColorFilter();
要從 XML 執行此操作,您可以添加 background 屬性以在 layout.xml 中使用任何可繪制資源作為背景執行相同的操作,方法是添加:
android:background="@drawable/mydrawable"
如果您有幾個具有相同樣式配置的 EditText,為了避免為每個 EditText 設置屬性,您可以覆蓋 EditText 的默認屬性,定義一個自定義樣式,就像這里完成的那樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.