2017-02-14 6 views
0

Ich entwickle eine App, in der ich eine Aktivität habe, die als "AboutPreference" bekannt ist, die PreferenceActivity erweitert und ich eine Symbolleiste in postCreate() Methode hinzugefügt hatte. Problem ist, dass ich "homeAsUpIndicator" -Farbe von Schwarz zu Weiß ändern möchte. Wie kann ich tun, dassWie ändert man die Farbe von HomeAsUpIndicator in Android?

Code: -

protected void onPostCreate(Bundle savedInstanceState) { 
     super.onPostCreate(savedInstanceState); 

     LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent(); 
     Toolbar bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.about_toolbar, root, false); 
     root.addView(bar, 0); // insert at top 
     bar.setNavigationOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       finish(); 
      } 
     }); 

    } 

Symbolleiste

<android.support.v7.widget.Toolbar 
android:id="@+id/toolbar" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/colorPrimary" 
app:navigationIcon="?attr/homeAsUpIndicator" 
android:minHeight="?attr/actionBarSize" 
app:navigationContentDescription="@string/abc_action_bar_up_description" 
app:theme="@style/ToolTheme" 
app:title="About Us" 
tools:ignore="PrivateResource"/> 

und hier Stil ist

<style name="ToolTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="android:textStyle">bold</item> 
    <item name="android:textColor">@color/white</item> 
    <item name="android:textColorSecondary">@color/white</item> 
    <item name="android:textColorPrimaryInverse">@color/white</item> 
    <item name="android:textSize">20sp</item> 
    <item name="android:homeAsUpIndicator">@color/White</item> 
    <item name="colorPrimary">#F5560A</item> 
    <item name="colorPrimaryDark">@color/accent</item> 
    <item name="android:navigationBarColor">@color/accent</item> 
    <item name="colorAccent">@color/accent</item> 
</style> 
+2

http://stackoverflow.com/questions/26439572/how- angeben to-style-the-drawerarrowtoggle-from-android-appcompat-v7-21-library – Raghunandan

Antwort

4

von Navigation Symbol in der Symbolleiste zugreifen, können wir Farbe

ändern
toolbar.getNavigationIcon().setColorFilter(color, PorterDuff.Mode.SRC_IN); 

Wenn es diese ein eigenes Bild verwenden können

toolbar.getNavigationIcon().mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN); 
+0

was werde ich anstelle von "color" eingeben – Ravi

+0

pass 'int color' oder was immer du willst Farbe oder' Color.RED' –

+0

@ Ravi können Sie Color.rgb verwenden (int rot, int grün, int blau) –

1

Sie nicht versuchen, zu arbeiten und das gleiche in verschiedenen Schnitten, wie unten

<item name="homeAsUpIndicator">@drawable/ic_back</item> 
<item name="android:homeAsUpIndicator">@drawable/ic_back</item> 
Verwandte Themen