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 for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. PHP求助,求幫忙謝謝各位3. extra沒有加載出來4. mysql - php 如何網(wǎng)址中出現(xiàn)該頁標(biāo)題?5. javascript - 天貓首頁首屏數(shù)據(jù)來源6. javascript - 釘釘?shù)膃xcel, word文件預(yù)覽是直接用的微軟的office web app,不犯法嗎?7. 關(guān)于Mysql數(shù)據(jù)表行轉(zhuǎn)列8. django進(jìn)行數(shù)據(jù)庫的查詢9. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時間會消失是什么情況?10. mysql - 為什么where條件中or加索引不起作用?
