久久久久久久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 | 九九在线视频 | 日日天天| www四虎影视 | 欧美性受 | 中文字幕国产 | av黄色在线| 日韩在线免费视频 | 国产主播第一页 | 91视频国产区| 久久国产精品一区二区三区 | 亚洲一区二区三区欧美 | www.久久久.com | 久久精品16 | 狠狠视频 | 中文字幕一区二区在线观看 | 亚洲国产精品视频 | 久久极品 | 亚洲人成人一区二区在线观看 | 久久一区二区三区四区 | 在线观看你懂的网站 | 最新av在线网址 | 中文字幕一区二区三区四区五区 | 色在线视频网站 | 成人国内精品久久久久一区 | 色接久久 | 久久久.com| 中文字幕一区二区三区精彩视频 | 99亚洲精品视频 | 亚洲国产精品一区 | 午夜伊人 | 国产日韩欧美在线观看 | 亚洲成人av | 天堂视频免费 | 日本成人一区二区 | 一区二区三区免费看 | 久久久91精品国产一区二区三区 | 91久久精品一区二区二区 | 91精品一区二区 | 最近日韩中文字幕 | 中文欧美日韩 |