2016-01-19 12 views
9

カスタマイズしたアイコンをナビゲーションドロワーのメニューに入力したいとします。ただし、アプリケーションを実行すると、アイコンの影だけが表示されます。イメージを正しく表示するにはどうしたらいいですか?ここでナビゲーションドロワーのメニューアイコンが正しく表示されない

enter image description here

メニューactivity_main_drawer.xmlのためのXMLファイルです:ここで

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
    <group android:checkableBehavior="single"> 
     <item 
      android:id="@+id/recent_picture" 
      android:icon="@mipmap/ic_recent" 
      android:title="Import" /> 
     <item 
      android:id="@+id/nav_gallery" 
      android:icon="@drawable/ic_menu_gallery" 
      android:title="Gallery" /> 
     <item 
      android:id="@+id/nav_slideshow" 
      android:icon="@drawable/ic_menu_slideshow" 
      android:title="Slideshow" /> 
     <item 
      android:id="@+id/nav_manage" 
      android:icon="@drawable/ic_menu_manage" 
      android:title="Tools" /> 
    </group> 
</menu> 

は、ナビゲーションビューでのXMLのレイアウトです:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <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:menu="@menu/activity_main_drawer" /> 
</android.support.v4.widget.DrawerLayout> 

別drawables.xmlがあります値フォルダにあるファイル

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
<item name="ic_recent_picture" type="drawable">@mipmap/ic_recent</item> 
<item name="ic_menu_gallery" type="drawable">@drawable/ic_menu_gallery</item> 
<item name="ic_menu_slideshow" type="drawable">@android:drawable/ic_menu_slideshow</item> 
<item name="ic_menu_manage" type="drawable">@android:drawable/ic_menu_manage</item> 
<item name="ic_menu_share" type="drawable">@android:drawable/ic_menu_share</item> 
<item name="ic_menu_send" type="drawable">@android:drawable/ic_menu_send</item> 

+0

を行ったように描画可能anydpiの描画可能なために、あなたのリソースファイルを移動したい場合がありますイメージを 'drawable'フォルダにコピーする –

+0

@cwfei、私はdrawableフォルダにイメージを置こうとしましたが、同じエラーを返します.. – michelletbs

+0

xmlファイルのリファレンスを' android:icon = "@ drawable/ic_recent 「画像をドロウアブルフォルダに移動したときは? –

答えて

0

あなたはそれが表示されるかどうかを確認するために別の画像に変更しようとしましたか?

<item name="ic_recent_picture" type="drawable">@mipmap/ic_recent</item> 

パス@mipmapには正しい画像が含まれていますか?

+0

私は、テンプレートからあらかじめ生成されたイメージを置き換えました。 android:icon = "@ drawable/ic_menu_gallery"しかし、自分のカスタマイズしたイメージを置くと、その灰色の四角形が表示されます。 – michelletbs

+0

画像をドロウアブルフォルダに入れてください... –

+0

こんにちは@Weverton Peron、これはアイコンから色合いモードを削除するには、このコードを入力して動作します。 navigationView.setItemIconTintList(null); – michelletbs

23

これは、setItemIconTintList(null)によってアイコンから色合いの効果を取り除いて動作します。下のコード行をnavigationViewの下に置きます。

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
navigationView.setItemIconTintList(null); 
navigationView.setNavigationItemSelectedListener(this); 
+1

Thanks Michelletbs、navigationView.setItemIconTintList(null);私の問題を解決しました。 – Sally

+0

偉大な解決策は、非常にうまく動作します。下位互換性があると思われ、前のロリポップはまだ動作しています。ありがとう! – TryTryAgain

+0

素晴らしい!もう1つの解決方法は2色の交換だけです:http://stackoverflow.com/questions/30967851/change-navigation-view-item-color-dynamicly-android – CoolMind

0

それでも色合いを除去することによって、問題を解決していない場合、あなたは(Poject Viewを使用)の代わりに私が入れてみ

関連する問題