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

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

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

問題描述

限時送ChatGPT賬號..

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

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

參考:

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

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

解決方案

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

在 Kotlin 中這非常簡單:

1.定義這個擴(kuò)展方法:

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.
    }
}

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

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

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
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 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 一区二区三区四区国产 | 亚洲精品电影网在线观看 | 亚洲精品一区久久久久久 | 久久久久久看片 | 国精久久| 日韩1区| 成人一区二 | 国产精品视频久久久 | 久久久精品一区二区三区 | 亚洲区在线 | 国产91综合一区在线观看 | 天堂久久网 | 中文字幕11页 | 国产高清视频在线 | 欧美一区二区在线播放 | 亚洲va国产日韩欧美精品色婷婷 | 羞羞视频网站免费观看 | 五月婷婷中文 | 欧美中文字幕一区二区三区亚洲 | 精品一区二区免费视频 | www免费视频 | 久久国内精品 | 免费h在线 | 成人午夜黄色 | 精品一区久久 | 99精品亚洲国产精品久久不卡 | 久久免费电影 | 色资源在线视频 | 色爱综合 | 美女久久久久久久 | 欧美日韩电影一区二区 | 国产精品视频一区二区三区 | 美女黄网 | 国产精品入口麻豆www | 成人国产在线视频 | 拍戏被cao翻了h承欢 | 久久精品影视 | 欧美一区二区三区在线免费观看 | 国产特级毛片aaaaaa | 成人午夜在线 | 欧美性影院 |