2

Als wir begannen, unsere App auf Android 6.0-Geräten zu testen, ist die Symbolleiste (Aktionsleiste) weiß. Es verwendet nicht die Farben, die wir in styles.xml angegeben haben. Dies hat für alle Pre-Marshmallow-Geräte funktioniert. Wer weiß, warum das so sein könnte? Ich konnte bei Google nichts darüber finden.Symbolleiste wird weiß (Stil/Farbe nicht angewendet) in Android 6.0 Marshmallow

Einige Code:

MainActivity.java

public class MainActivity extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
} 
} 

activity_main.xml

<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" 
tools:context="com.example.swekjaks.actionbartest.MainActivity"> 
<include android:id="@+id/toolbar" 
     layout="@layout/tool_bar" /> 

</RelativeLayout> 

tool_bar.xml

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:background="@color/PrimaryColor" 
           android:foreground="@color/white" 
           android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

</android.support.v7.widget.Toolbar> 

styles.xml

<resources xmlns:tools="http://schemas.android.com/tools"> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar"> 
    <item name="android:actionBarStyle" tools:targetApi="11">@style/RelacomActionBar</item> 

    <!-- Support library compatibility --> 
    <item name="actionBarStyle">@style/RelacomActionBar</item> 

    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

<!-- ActionBar styles --> 
<style name="RelacomActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="android:background">@color/colorPrimary</item> 

    <!-- Support library compatibility --> 
    <item name="background">@color/colorPrimary</item> 
</style> 

</resources> 
+0

Sie setzen Androiden: Vordergrund = "@ Farbe/weiß", also welche Farbe erwarten Sie es zu sein? – Egor

+0

Süß. Das hat funktioniert. Aber warum verhält es sich so? Es ist nicht sehr klar, dass der Vordergrund die Hintergrundfarbe der Symbolleiste ist. – exkoria

Antwort

0

Kopieren Sie die benutzerdefinierten styles und colors-styles.xml (v21) auch, und es wird funktionieren.

enter image description here

Der Pfad für die styles.xml (v21) ist:

\app\src\main\res\values-v21\styles.xml 
+1

Danke für die Antwort, aber leider funktioniert es nicht. Es ist immer noch weiß auf Android 6.0. – exkoria

0

Ich denke, es ist ein Fehler in der Design-Bibliothek. Ich benutze Bibliotheken 23.3.0. und der Fehler tritt immer noch auf. Problemumgehung dafür ist das Hinzufügen von View, die fast keinen Platz benötigt und unsichtbar sein kann. Siehe die Struktur unten.

<android.support.v4.widget.NestedScrollView 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

</android.support.v4.widget.NestedScrollView> 

<android.support.design.widget.AppBarLayout> 

    <android.support.v7.widget.Toolbar 
     app:layout_scrollFlags="scroll|enterAlways" /> 

    <android.support.design.widget.TabLayout 
     app:layout_scrollFlags="scroll|enterAlways" /> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height=".3dp" 
     android:visibility="visible"/> 

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

dies für mich gearbeitet. lassen Sie die Leute wissen, ob es für Sie funktioniert. für weitere Informationen wenden Sie sich bitte https://code.google.com/p/android/issues/detail?id=178037

Verwandte Themen