0

Um es so kurz wie möglich zu halten.TextInputLayout und AutoCompleteTextView Hintergrund sieht in der Vorschau gut aus, aber auf dem Gerät ist es immer weiß

Das ist mein Stil für 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> 

Und das ist die Umsetzung im Layout

<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> 

Und das ist, was ich auf dem Gerät erhalten (sowohl physisch als auch emulierte): enter image description here

Aber das ist, was ich eigentlich will und Android Studio Vorschau tatsächlich zeigt es richtig, es wird nur nicht kompilieren Übrigens:

enter image description here

Irgendwelche Ideen, wie diese bitte sortiert erhalten? Ich habe einige Tage vergeudet, um dieses herauszufinden, aber kann einfach nicht das Problem

Vielen Dank im Voraus! Sloba

Antwort

1

Das Problem liegt in Ihren Stilen. Sie wenden Widget.AppCompat.AutoCompleteTextView auf TextInputLayout mit den Ergebnissen an, die Sie sehen. Sie können diesen übergeordneten Stil in AppTheme ändern oder android:theme="@style/TextLabel" in die AutoCompleteTextView verschieben und nicht das übergeordnete Element ändern. Ich zeige den ersten Weg unten.

Dieses kleine Video zeigt die Änderungen, die ich gemacht habe, um zu bekommen, was ich denke, was Sie wollen. Ich habe ein paar Dinge hinzugefügt, um besser zu zeigen, wie es funktioniert. Es ist vielleicht nicht 100% von dem, was Sie brauchen, aber es sollte Sie über die Schwelle bringen.

Demo video

Hier ist der 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> 

Und 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

OMG, ich danke Ihnen so sehr das Problem war, dass ich tatsächlich anwandte der TextLabel-Stil mit dem Attribut 'style', aber ich sollte ihn mit dem Attribut 'android: theme' anwenden. –

Verwandte Themen