android - TextInputLayout的空白顯示問題
問題描述
首先我這里由于歷史原因不能繼承AppCompactActivity,所以還是以前的Activity。我引入TextInputLayout它報了inflater之類的錯誤,那我就給Activity設(shè)置主題:
<activity android:name='.LoginAndRegistActivity' android:screenOrientation='portrait' android:theme='@style/Base.Theme.AppCompat'></activity>
這樣的話TexuInputLayout就能在這個Activity里使用了,當(dāng)它一開始是顯示空白的,只有當(dāng)它獲取到了點擊焦點它的提示效果才能顯示出來,一旦失去了焦點,它就又變成了白色。那么我就給這個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的效果就能顯示出來了。但現(xiàn)在進(jìn)一步的問題是,如果一開始這個TextInputLayout是隱藏的,也就是visibility是gone的時候,當(dāng)它第一次被visiable的時候,還是顯示空白,只有當(dāng)點擊了之后才會顯示正常,以后再隱藏再顯示都是正常的。如圖:
在登錄頁的時候,第二個TextInputLayout是gone的,當(dāng)切換到注冊時才出現(xiàn),但它此時是白色的,而只有當(dāng)我切換回登錄或是點擊這第二個TextInputLayout的時候,hint才會出現(xiàn),就沒問題了。
問題解答
回答1:好吧.....自己把問題給解決了,首先我在xml布局文件里,不對edittext寫hint,而是轉(zhuǎn)到它的TextInputLayout里寫hint,運行的時候發(fā)現(xiàn)6.0可以正常顯示了,但發(fā)現(xiàn)4.x的雖然edittext有顯示hint,但沒有動畫效果.....然后我就換成在代碼里對TextInputLayout去set hint,沒想到現(xiàn)在就有動畫效果了.....雖然我也不知道是怎么回事。
相關(guān)文章:
1. docker 17.03 怎么配置 registry mirror ?2. javascript - sublime快鍵鍵問題3. javascript - immutable配合react提升性能?4. DADB.class.php文件的代碼怎么寫5. javascript - html5多個label中其中一個觸發(fā)change,如何判斷是哪一個出發(fā)了change6. phpstudy8.1支持win11系統(tǒng)嗎?7. mysql事務(wù)回滾定位8. css - 寫頁面遇到個布局問題,求大佬們幫解答,在線等,急!~9. 實現(xiàn)bing搜索工具urlAPI提交10. 配置Apache時,添加對PHP的支持時語法錯誤

網(wǎng)公網(wǎng)安備