久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使必填字段的 TextInputLayout 提示星號為紅色

How to make TextInputLayout hint asterisk red for required fields(如何使必填字段的 TextInputLayout 提示星號為紅色)
本文介紹了如何使必填字段的 TextInputLayout 提示星號為紅色的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在使用設計支持庫中的 TextInputLayout 時,是否可以只將提示中的星號設為紅色?我已經看到有關樣式化整個提示的信息,但這有點復雜,因為只有 * 應該是紅色的,而不是整個消息.

Material Design 示例顯示了這一點,但設計庫似乎沒有任何選項可以使用 TextInputLayout 和 EditText 以這種方式設置樣式.

參考:

我研究了將提示設置為 SpannableString(請參閱此處 如何在 OnFocusChangeListener 中的 <string> entry 中獲取紅色星號(請參見此處 對文本輸入布局內的編輯文本(紅色星號)具有強制符號),但提示是一個字符序列.

有什么方法可以在不擴展 TextInputLayout 的情況下做到這一點?

解決方案

Material Design 為作為提示文本一部分的必填字段指定一個星號,并且顏色相同(不像您在問題中顯示的那樣為紅色).

在 Kotlin 中這非常簡單:

1.定義這個擴展方法:

fun TextInputLayout.markRequired() {提示 = "$提示 *"}

2.使用它:

input_first_name.markRequired()

如果您仍然想要星號紅色,盡管 Material Design 指南不鼓勵您,您可以這樣使用 AndroidX Core KTX:

fun TextInputLayout.markRequiredInRed() {提示 = buildSpannedString {附加(提示)color(Color.RED) { append(" *") }//注意空格前綴.}}

Is it possible to make just the asterisk in the hint red when using a TextInputLayout from the design support library? I have seen information on styling the entire hint, but this is a little more complex since only the * should be red, not the whole message.

The Material Design example shows this, but the design library doesn't seem to have any option to style it this way using a TextInputLayout and EditText.

Reference: https://www.google.com/design/spec/components/text-fields.html#text-fields-required-fields

Example (the top, with focus, has the red asterisk; the bottom without focus does not have a red asterisk):

I looked into setting the hint to a SpannableString (see here How to get a red asterisk in a <string> entry) in an OnFocusChangeListener (see here Having the mandatory symbol to the edit text (red color asterisk) which is inside the textinputlayout), but the hint is a CharSequence.

Is there any way to do this without extending TextInputLayout?

解決方案

Material Design specify an asterisk for the required fields that is part of the hint text, and of the same color (not in red like you showed in your question).

In Kotlin this is really simple:

1.Define this extension method:

fun TextInputLayout.markRequired() {
    hint = "$hint *"
}

2.Use it:

input_first_name.markRequired()

If you still want the asterisk red, despite being discouraged by Material Design guidelines, you can use AndroidX Core KTX that way:

fun TextInputLayout.markRequiredInRed() {
    hint = buildSpannedString {
        append(hint)
        color(Color.RED) { append(" *") } // Mind the space prefix.
    }
}

這篇關于如何使必填字段的 TextInputLayout 提示星號為紅色的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 狠狠躁躁夜夜躁波多野结依 | 久久色视频 | 国产真实乱对白精彩久久小说 | 欧美a在线观看 | 一区二区成人在线 | 久久精品一区二区视频 | 天堂亚洲 | 999在线精品| 看片国产 | 亚洲精品一区二区三区中文字幕 | 少妇一区在线观看 | 国产真实乱全部视频 | 天天看天天干 | 国产精品日日做人人爱 | 欧美日韩精品一区二区三区视频 | 国产激情在线观看 | 久久一| 日韩中文一区 | 中文字幕亚洲视频 | 亚洲 成人 av| 国产精品日韩欧美一区二区三区 | 中文字幕第十五页 | 国产精品视频一区二区三区不卡 | 午夜影院在线免费观看视频 | 人人人艹| 久久精品欧美一区二区三区不卡 | 亚洲欧美一区二区三区国产精品 | 免费看一区二区三区 | 亚洲国产一区二区在线 | 波波电影院一区二区三区 | 欧美日韩国产在线观看 | 国产精品视频网 | 成人精品一区二区三区四区 | 天天操夜夜操 | 精品成人| 黄网站涩免费蜜桃网站 | 久久av一区 | 少妇一级淫片免费放播放 | 怡红院免费的全部视频 | 欧美一级毛片在线播放 | 亚洲欧美成人影院 |