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

使用設計支持庫時 EditText getHint() 返回 null

EditText getHint() returns null when using design support library(使用設計支持庫時 EditText getHint() 返回 null)
本文介紹了使用設計支持庫時 EditText getHint() 返回 null的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

將 EditText 與 Design lib(版本 22.2.1)結合使用時,TextInputLayout 以編程方式獲取提示返回 null.

When using EditText in combination with Design lib's (ver 22.2.1) TextInputLayout getting hint programmatically returns null.

我正在嘗試以編程方式將星號*"附加到必填字段,因此 EditText.getHint() 但它返回 null 的事實在這種情況下是一個問題.

I'm trying to append asterisk '*' to a mandatory field programmatically, hence EditText.getHint() but the fact that it returns null is an issue in this case.

EditText editText = (EditText) findViewById(R.id.edit2);
String hint = String.format("%s *", editText.getHint());
editText.setHint(hint);

一個簡單的代碼說明:布局.xml:

A simple code illustration: Layout.xml:

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <EditText
            android:id="@+id/edit2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hello_world"
            android:inputType="text"/>
</android.support.design.widget.TextInputLayout>

Java:

EditText editText = (EditText) findViewById(R.id.edit2);
if (editText.getHint() == null) throw new AssertionError("Hint should not be null");

依賴:編譯'com.android.support:design:22.2.1'

dependency: compile 'com.android.support:design:22.2.1'

以前相關的問題 這里!

推薦答案

實際上提示移動到 EditText 視圖周圍的父視圖 TextInputLayout:

Actually the hint moves to the parent view TextInputLayout that surrounds the EditText view:

你可以得到這樣的提示:

You can get the hint like this:

android.support.design.widget.TextInputLayout parent = (android.support.design.widget.TextInputLayout) yourEditText.getParent();
String hint = parent.getHint().toString();

如果你想添加 * 讓它像這樣:

And if you want to add * make it like this:

parent.setHint(parent.getHint() + "*");

編碼愉快!:)

這篇關于使用設計支持庫時 EditText getHint() 返回 null的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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問題)
主站蜘蛛池模板: 精品日本久久久久久久久久 | 在线观看 亚洲 | 日韩一区二区在线视频 | 久久国产精品色av免费观看 | 一区二区三区视频在线观看 | 亚洲一二三区精品 | 日韩爱爱网| 99久久婷婷国产综合精品电影 | 秋霞在线一区 | 成人精品一区二区三区四区 | 精品欧美 | 久久成人国产精品 | 国产精品亚洲一区二区三区在线 | 日韩一区二区三区精品 | 国产福利在线 | 一区二区在线不卡 | 国产精品激情在线 | 免费精品久久久久久中文字幕 | 精品一二三区在线观看 | 欧美a在线 | 在线观看免费av网 | 国产毛片久久久 | 久草在线免费资源 | 国产亚洲精品久久久久久牛牛 | 欧美极品一区二区 | 天堂中文资源在线 | 国产a爽一区二区久久久 | 国产中文字幕在线观看 | 91精品国产综合久久精品 | 国产一区二区免费 | 中文字幕日韩一区 | 久久综合伊人 | 一区日韩| 日韩精品专区在线影院重磅 | 国产伊人久久久 | 91偷拍精品一区二区三区 | 亚洲一区日韩 | 一区二区三区回区在观看免费视频 | 男人的天堂久久 | 欧美jizzhd精品欧美巨大免费 | 狠狠色综合网站久久久久久久 |