enter image description here我想將edittext中的提示*設置爲紅色作爲必填字段。請給我建議如何在textinputlayout中設置提示* Android
我想這顆星只有紅色等,因爲它是
enter image description here我想將edittext中的提示*設置爲紅色作爲必填字段。請給我建議如何在textinputlayout中設置提示* Android
我想這顆星只有紅色等,因爲它是
你可以簡單地做像下面一個
<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"
/>
請仔細閱讀請 –
請參閱編輯的文章作爲您的圖片說 –
您已更改圖片確定您有紅色文字圖片 –
存放於字符串的字符串文件中像這樣(如果你想使所需的電子郵件):
<string name="email">Email<font fgcolor="red">*</font></string>
,並在您EDITTEXT設置提示是這樣的:
android:hint="@string/email"
在XML代碼在你strings.xml
添加這個提示是這樣android:hint="Put your hint text"
您是否知道問題?它的工作原理是 –
添加下面string
爲hints
。
<string name="hints"><![CDATA[Member ID(Don\'t include dash or space)<font color=\'#cc0029\'>*</font>]]></string>
2.編程設置該從你的Activity
類string
爲hint
文本。
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:
希望這將有助於〜
。謝謝你節省我的時間。 –
樂於助人。如果我的答案可以幫助您,請點擊勾號將其標記爲已接受的答案。提前致謝 :) – FAT
^h你有沒有顯示你的提示?它是編輯文本字段上方的文本視圖,還是使用文本輸入佈局? –
在問一個問題之前,你甚至已經使用了Google嗎? – azizbekian
使用ForegroundSpan只使星形成紅色。您可以在這裏找到示例實現http://stackoverflow.com/a/3514435/4321808 –