2017-01-24 4 views
1

In meiner Navigationsleiste sieht mein Listenansichtssymbol wie folgt aus: check image. Das bedeutet, dass ich das Symbol auf den Hintergrund gelegt habe.Hintergrund der Navigationsleiste festlegen

ich durch das Rahmenlayout weiß, kann ich das Symbol auf einem Bild setzen, aber ich bin verwirrt, wie kann ich es tun, wenn es in einem res/menu Ordner

menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
    <group android:checkableBehavior="single"> 
      <item 
      android:id="@+id/nav_home" 
      android:icon="@drawable/ic_home_white_24dp" 
      android:title="@string/nav_item_home" /> 

     <item 
      android:id="@+id/appointment_history" 
      android:icon="@drawable/appointment_icon" 
      android:title="@string/nav_history" /> 
     <item 
      android:id="@+id/contact_us" 
      android:icon="@drawable/contact_us_icon" 
      android:title="@string/nav_contact_us" /> 

     <item 
      android:id="@+id/nav_settings" 
      android:icon="@drawable/setting_icon" 
      android:title="@string/nav_setting" /> 
    </group> 
</menu> 
erklärt hat

new Image

Style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- 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="RatingBar" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorControlNormal">#00BFF3</item> 
    <item name="colorControlActivated">#00BFF3</item> 
</style> 
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> 
    <item name="android:windowBackground">@drawable/background_splash</item> 
</style> 

<style name="MyCustomToolBarTheme" parent="ThemeOverlay.AppCompat.Light"> 
    <item name="android:textColorPrimary">@color/colorAccent</item> 


</style> 

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

<style name="MyMaterialTheme" parent="MyMaterialTheme.Base"> 

</style> 

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="windowNoTitle">true</item> 
    <item name="windowActionBar">false</item> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 
012 v

<style name="MyMaterialTheme" parent="MyMaterialTheme.Base"> 
    <item name="android:windowContentTransitions">true</item> 
    <item name="android:windowAllowEnterTransitionOverlap">true</item> 
    <item name="android:windowAllowReturnTransitionOverlap">true</item> 
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item> 
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item> 
</style> 

Antwort

1

Zuerst müssen Sie das Symbol Tönung auf null gesetzt.

navigationView.setItemIconTintList(null); 

Dann könnten Sie eine XML-ziehbar wie dies in diesem Beispiel erstellen i nennen wird es rounded_corner_home.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item > 
    <shape android:shape="rectangle"> 
     <solid android:color="#007f12" /> 
     <corners android:radius="4dp" /> 
    </shape> 
    </item> 
    <item> 
     <bitmap android:src="@drawable/ic_home_white_24dp"/> 
    </item> 
</layer-list> 

Dann ändern Sie die Symbol-Anstand des Menüelements.

<item 
    android:id="@+id/nav_home" 
    android:icon="@drawable/rounded_corner_home" 
    android:title="@string/nav_item_home" /> 

Hier ein Screenshot des Ergebnisses: Screen

+0

nicht Sir Arbeits –

+0

ich weitere Informationen und einen Screenshot von dem Ergebnis hinzugerechnet wurde. –

+0

Sir Ihre Lösung ist teilweise funktioniert ... auf Kitkat funktioniert es perfekt, aber auf Lollipop ist es zeigt den transparenten Hintergrund –

0
Using this code you can change the color of drawer icon : 

o NavigationView (it is located in activity_main.xml layout file) The default tint is black but you can use an even darker shade of black by using #000000 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:itemIconTint="#000000" 
    app:menu="@menu/activity_main_drawer" /> 
+0

eigentlich ich bin nicht über die Symbol Tönung sprechen, ist meine Sorge über das Symbol Hintergrund überprüfen neues Bild bitte –

+0

okkk ich werde es überprüfen. @DhruvTyagi –

+0

Er ist teilweise richtig, der Farbton wird das ganze Symbol haben nur eine Farbe und Sie wollen und ein Symbol mit zwei Farben, aber die Einstellung auf weiß wird nicht helfen. –

Verwandte Themen