0

要儘可能短。TextInputLayout和AutoCompleteTextView背景在預覽中看起來很好,但在設備上始終是白色的

這是我的風格TextInputLayout

<style name="TextLabel" parent="Widget.AppCompat.AutoCompleteTextView"> 
    <!-- Hint color and label color in FALSE state --> 
    <item name="android:textColorHint">@color/pure_white</item> 
    <!-- Label color in TRUE state and bar color FALSE and TRUE State --> 
    <item name="colorAccent">@color/pure_white</item> 
    <item name="colorControlNormal">@color/pure_white</item> 
    <item name="colorControlActivated">@color/pure_white</item> 
    <!-- When everything else failed I tried this but with no effect --> 
    <item name="android:background">@android:color/transparent</item> 
</style> 

而且這是在佈局

<android.support.design.widget.TextInputLayout 
     android:theme="@style/TextLabel" 
     android:layout_margin="@dimen/activity_margin_basic_double" 
     android:layout_centerInParent="true" 
     android:id="@+id/team_name_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <AutoCompleteTextView 
      android:id="@+id/new_team_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/prompt_team_create" 
      android:maxLines="1" /> 

    </android.support.design.widget.TextInputLayout> 

實施而這就是我得到的設備上(包括物理和仿真): enter image description here

但是,這是我真正想要的和Android Studio預覽實際顯示它正確,它只是不會編譯這個方法:

enter image description here

任何想法如何得到這個排序嗎?我浪費了幾天的時間試圖找出這一個,但只是不能解決問題

非常感謝提前! Sloba

回答

1

問題出現在您的樣式中。您正在將Widget.AppCompat.AutoCompleteTextView應用於TextInputLayout,並顯示您看到的結果。您可以將此父級樣式更改爲AppTheme或將android:theme="@style/TextLabel"更改爲AutoCompleteTextView,並且不更改父級。我展示了下面的第一種方法。

這個小視頻顯示了我爲了得到我認爲是你想要的東西而做出的改變。我添加了一些內容來更好地展示它是如何工作的。它可能不是你所需要的100%,但它應該讓你超過門檻。

Demo video

這裏是XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFcc9c00" 
    android:orientation="vertical"> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/team_name_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:theme="@style/TextLabel"> 

     <AutoCompleteTextView 
      android:id="@+id/new_team_name" 
      android:layout_width="match_parent" 
      android:hint="Choose a Team Name" 
      android:layout_height="wrap_content" 
      android:maxLines="1" /> 
    </android.support.design.widget.TextInputLayout> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/team_name_container" 
     android:layout_margin="8dp" 
     android:hint="EditText hint" /> 
</RelativeLayout> 

而styles.xml:

<resources> 
    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 
    <style name="TextLabel" parent="AppTheme"> 
     <!-- Hint color and label color in FALSE state --> 
     <item name="android:textColorHint">@android:color/white</item> 
     <!-- Label color in TRUE state and bar color FALSE and TRUE State --> 
     <item name="colorAccent">@android:color/white</item> 
     <item name="colorControlNormal">@android:color/white</item> 
     <item name="colorControlActivated">@android:color/white</item> 
    </style> 
</resources> 
+0

媽呀,太感謝你了,問題是,我在實際應用中具有'style'屬性的TextLabel樣式,但是我應該使用'android:theme'屬性來應用它。 –

相關問題