2017-04-27 75 views
-1

enter image description here我想將edittext中的提示*設置爲紅色作爲必填字段。請給我建議如何在textinputlayout中設置提示* Android

我想這顆星只有紅色等,因爲它是

+0

^h你有沒有顯示你的提示?它是編輯文本字段上方的文本視圖,還是使用文本輸入佈局? –

+1

在問一個問題之前,你甚至已經使用了Google嗎? – azizbekian

+1

使用ForegroundSpan只使星形成紅色。您可以在這裏找到示例實現http://stackoverflow.com/a/3514435/4321808 –

回答

0

你可以簡單地做像下面一個

<android.support.design.widget.TextInputEditText 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:hint="Add text here (demo text)*" 
      android:textColorHint="@android:color/holo_red_dark" 
      /> 
+1

請仔細閱讀請 –

+0

請參閱編輯的文章作爲您的圖片說 –

+0

您已更改圖片確定您有紅色文字圖片 –

1

存放於字符串的字符串文件中像這樣(如果你想使所需的電子郵件):

<string name="email">Email<font fgcolor="red">*</font></string> 

,並在您EDITTEXT設置提示是這樣的:

android:hint="@string/email" 
0

在XML代碼在你strings.xml添加這個提示是這樣android:hint="Put your hint text"

+1

您是否知道問題?它的工作原理是 –

1

添加下面stringhints

<string name="hints"><![CDATA[Member ID(Don\'t include dash or space)<font color=\'#cc0029\'>*</font>]]></string> 

2.編程設置該從你的Activitystringhint文本。

EditText editText = (EditText) findViewById(R.id.edit_member_id); 
editText.setHint(Html.fromHtml(getString(R.string.hints))); 

這是XML格式的EditText

<EditText 
    android:id="@+id/edit_member_id" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

OUTPUT:

enter image description here

希望這將有助於〜

+0

。謝謝你節省我的時間。 –

+0

樂於助人。如果我的答案可以幫助您,請點擊勾號將其標記爲已接受的答案。提前致謝 :) – FAT

相關問題