android - TextInputLayout的空白顯示問(wèn)題
問(wèn)題描述
首先我這里由于歷史原因不能繼承AppCompactActivity,所以還是以前的Activity。我引入TextInputLayout它報(bào)了inflater之類的錯(cuò)誤,那我就給Activity設(shè)置主題:
<activity android:name='.LoginAndRegistActivity' android:screenOrientation='portrait' android:theme='@style/Base.Theme.AppCompat'></activity>
這樣的話TexuInputLayout就能在這個(gè)Activity里使用了,當(dāng)它一開(kāi)始是顯示空白的,只有當(dāng)它獲取到了點(diǎn)擊焦點(diǎn)它的提示效果才能顯示出來(lái),一旦失去了焦點(diǎn),它就又變成了白色。那么我就給這個(gè)TextInputLayout設(shè)置了主題:
<android.support.design.widget.TextInputLayout android: android:layout_width='match_parent' android:layout_height='134px' android:layout_marginLeft='30px' android:layout_marginRight='30px' android:gravity='center_vertical' android:orientation='vertical' android:focusable='true' android:focusableInTouchMode='true' android:theme='@style/text_input_layout_theme' > <com.ugiant.widget.ClearEditTextandroid: android:layout_width='match_parent'android:layout_height='wrap_content'android:background='@null'android:hint='@string/code'android:imeOptions='actionNext'android:textColor='@color/v4_text_color_black_87'android:textCursorDrawable='@color/primaryColor'android:textSize='16sp' /> <View /></android.support.design.widget.TextInputLayout>
<!-- TextInputLayout的樣式--> <style name='text_input_layout_theme' ><!-- Hint color and label color in FALSE state --><item name='android:textColorHint'>@color/primaryColor</item><!--<item name='android:textColor'>@color/v4_text_color_black_87</item>--> </style>
這樣TextInputLayout的效果就能顯示出來(lái)了。但現(xiàn)在進(jìn)一步的問(wèn)題是,如果一開(kāi)始這個(gè)TextInputLayout是隱藏的,也就是visibility是gone的時(shí)候,當(dāng)它第一次被visiable的時(shí)候,還是顯示空白,只有當(dāng)點(diǎn)擊了之后才會(huì)顯示正常,以后再隱藏再顯示都是正常的。如圖:
在登錄頁(yè)的時(shí)候,第二個(gè)TextInputLayout是gone的,當(dāng)切換到注冊(cè)時(shí)才出現(xiàn),但它此時(shí)是白色的,而只有當(dāng)我切換回登錄或是點(diǎn)擊這第二個(gè)TextInputLayout的時(shí)候,hint才會(huì)出現(xiàn),就沒(méi)問(wèn)題了。
問(wèn)題解答
回答1:好吧.....自己把問(wèn)題給解決了,首先我在xml布局文件里,不對(duì)edittext寫(xiě)hint,而是轉(zhuǎn)到它的TextInputLayout里寫(xiě)hint,運(yùn)行的時(shí)候發(fā)現(xiàn)6.0可以正常顯示了,但發(fā)現(xiàn)4.x的雖然edittext有顯示hint,但沒(méi)有動(dòng)畫(huà)效果.....然后我就換成在代碼里對(duì)TextInputLayout去set hint,沒(méi)想到現(xiàn)在就有動(dòng)畫(huà)效果了.....雖然我也不知道是怎么回事。
相關(guān)文章:
1. Python爬蟲(chóng)如何爬取span和span中間的內(nèi)容并分別存入字典里?2. mysql - 把一個(gè)表中的數(shù)據(jù)count更新到另一個(gè)表里?3. 請(qǐng)教使用PDO連接MSSQL數(shù)據(jù)庫(kù)插入是亂碼問(wèn)題?4. mysql - 分庫(kù)分表、分區(qū)、讀寫(xiě)分離 這些都是用在什么場(chǎng)景下 ,會(huì)帶來(lái)哪些效率或者其他方面的好處5. visual-studio - Python OpenCV: 奇怪的自動(dòng)補(bǔ)全問(wèn)題6. 視頻文件不能播放,怎么辦?7. mysql 查詢身份證號(hào)字段值有效的數(shù)據(jù)8. linux - Ubuntu下編譯Vim8(+python)無(wú)數(shù)次編譯失敗9. node.js - nodejs開(kāi)發(fā)中常用的連接mysql的庫(kù)10. python - 爬蟲(chóng)模擬登錄后,爬取csdn后臺(tái)文章列表遇到的問(wèn)題
