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

如何使必填字段的 TextInputLayout 提示星號(hào)為紅色

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

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

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

Material Design 示例顯示了這一點(diǎn),但設(shè)計(jì)庫(kù)似乎沒(méi)有任何選項(xiàng)可以使用 TextInputLayout 和 EditText 以這種方式設(shè)置樣式.

參考:

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

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

解決方案

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

在 Kotlin 中這非常簡(jiǎn)單:

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

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

2.使用它:

input_first_name.markRequired()

如果您仍然想要星號(hào)紅色,盡管 Material Design 指南不鼓勵(lì)您,您可以這樣使用 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 提示星號(hào)為紅色的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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)在展開(kāi)的 EditText 中的開(kāi)始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問(wèn)題)
主站蜘蛛池模板: 成人毛片在线播放 | 黄色大片免费在线观看 | 国产亚洲欧美一区二区 | 无遮挡毛片 | a免费视频| 日本一区二区三区在线视频 | 亚洲一区久久 | 亚洲一区二区三区在线播放 | 婷婷第四色 | 日本黄色免费 | 国产激情网站 | 自拍偷拍av | 日本a在线观看 | 欧美日韩第一区 | 黄色一级在线观看 | 一本色道久久综合亚洲精品小说 | 黄色一级大片在线免费看国产一 | 欧美操操操 | 双性呜呜宫交受不住了h | 亚洲一区二区av | 亚洲一区二区三区免费视频 | 女人一级一片30分 | 国产浮力第一页 | 日本欧美久久久久免费播放网 | 五月天激情国产综合婷婷婷 | 黄色片中文字幕 | 色妞网站| 97国产视频 | 中文字幕免费在线看线人动作大片 | 在线视频日本 | 久久伊人久久 | www.三级| 91亚色视频 | 中文字幕无人区二 | 超碰免费在线 | 欧美日韩国产一区 | 这里只有精品在线观看 | 欧美激情小视频 | 亚洲福利专区 | 亚洲天堂一区二区三区 | 91二区|