久久久久久久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片 | 波多野结衣乳巨码无在线观看 | 日韩精品视频免费播放 | 亚洲免费黄色 | 国产在线观看免费 | 97超碰免费 | 久久国产精品一区二区 | 91久久国产综合久久91精品网站 | 亚洲日本在线观看 | 国产成人精品自拍 | 日韩欧美视频一区 | 天天澡天天狠天天天做 | 国产成人亚洲精品自产在线 | 天天干天天操天天干 | 五月婷婷中文字幕 | 伊人色播 | avtt久久| 成人精品免费视频 | 男人天堂网av | 亚洲欧美在线一区 | 2018天天操| 欧美在线网址 | 成人午夜又粗又硬又大 | 日日爱视频 | 成人毛片网站 | 亚洲欧美一区二区三区在线 | 精品久久久久久久 | 精品国产aⅴ麻豆 | 免费黄色在线 | 国产一区精品视频 | 久热精品在线 | 日韩视频二区 | 午夜性影院 | 亚洲精品三区 | 亚洲一区在线观看视频 | 精品视频一区二区 | 亚洲九九夜夜 | 黄色小说在线免费观看 | 青青草国产成人av片免费 | 欧美做受喷浆在线观看 | av在线免费观看网站 |