Hi, create

<android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true"/> 

And I'm trying to stuff menu items there,

  AssetManager assetManager = getAssets(); InputStream istr = null; try { istr = assetManager.open("image.jpg"); } catch (IOException e) { e.printStackTrace(); } Bitmap bitmap = BitmapFactory.decodeStream(istr); Drawable icon = new BitmapDrawable(getResources(), bitmap); menu.add("Title").setIcon(icon); 

Pictures are in assets but dark gray squares appear in their place.

Tried to move them to drawable

 menu.add("title").setIcon(R.drawable.img); 

The result is absolutely the same ... What could it be? Is it really impossible to stuff raster images into standard NavigationView?

  • try .png - Kirill Stoianov
  • I tried ... it did not help - Andrey Shpileva
  • Tint works correctly, but it repaints the whole block, but does not give the desired result - Andrey Shpileva

1 answer 1

Pictures of assets should be in the assets folder, not in the drawable folder. In this case, the folder must be created using the studio, and not manually at the OS level. Try this:

 assetManager = getResources().getAssets(); InputStream stream; try { String someimage = ImageName.substring(0,15); stream = assetManager.open("image.jpg"); Drawable flag = Drawable.createFromStream(stream, someimage); imageView.setImageDrawable(flag); } 

As another option is to use a third-party library, for example, Picasso .