PeakGen
PeakGen

Reputation: 23015

Background drawable is not displaying in real device

Please have a look at the following XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@drawable/background_main" >
</RelativeLayout>

When I run this, all the tings are perfect and the background image of the main layout also get displayed in Emulator. But, when I run this code in Phone, the background image is missing! What is wrong?

Upvotes: 1

Views: 597

Answers (2)

PeakGen
PeakGen

Reputation: 23015

I found the issue by my self. My app is multi screen supporting so I had to put those images (with different sizes) into all the related drawable folders.

Upvotes: 1

Sujay Kumar
Sujay Kumar

Reputation: 558

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@drawable/background_main" >

xmlns:tools are most probably used for the activity the tools UI editor uses to render your layout (it will find the right theme based on the activity). So if you can just remove tools OR in .MainActivity java class. define your background source.

//outside your onCreate
RelativeLayout relativeLayout;
Context ctx;

//inside your onCreate
relativeLayout = new RelativeLayout(this);
relativeLayout.setBackgroundResource(R.drawable.background_main);
setContentView(relativeLayout);

Upvotes: 0

Related Questions