Jayizzle Jayizzle - 1 year ago 89
Android Question

Android Drawable Image not Showing

I am trying to programically set the background of my app with an image in my drawable-hdpi folder. It is only seeing the default ic_launcher file in R.drawable so when I go to set the background, its simply unexistant. I am using this class as a fragment class with a swipe menu so maybe that has something to do with it.

EDIT: I was able to set the background in my xml file, but I couldn't set the background in my oncreateview method.

public class inputClass extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.input_xml, container, false);


return rootView;

Answer Source

The problem is that your drawable image file is only available drawable-hdpi folder. In order to set the background properly, you can do two following ways.

  1. You should place your image file to all drawable directories. I mean you should put that image into drawable-ldpi, drawable-mdpi and so on. Also you should be careful about the size of the image because each folder corresponds to screen sizes. Please check out this API Guide

  2. Second way is the alternative for the first one. Create a directory within res/ folder and name it as drawable and then move your image file from drawable-hdpi to drawable.

Then, clean the project and relaunch.

Hope this may help.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download