Need help in customizing background drawable for Gallery wid

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Need help in customizing background drawable for Gallery wid

Postby silverburgh.meryl » Wed Feb 25, 2009 7:17 am

Hi,

I am trying to customize background drawable for Gallery widget in android.
So I took the Gallery1.java in APIDemo and try changing the background
drawable of Gallery.

In Gallery1.java, I add:
// Reference the Gallery view
Gallery g = (Gallery) findViewById(R.id.gallery);

g.setFocusable(true);
g.setFocusableInTouchMode(true);
g.setBackgroundResource(R.drawable.gallery_background_1);


In the gallery_background_1.xml, I have
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/blue_box" />
<item android:drawable="@drawable/red_box" />
</selector>

When I run in the emulator, I do see the red color as the background
of the gallery.
But I never see it changes to blue as I pressed the gallery.

Can you please tell me what am I missing?

Thank you for your help.

Here is the red_box and blue_box drawable:
blue_box.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#1e0000ff"/>
<padding android:left="1dp" android:top="1dp"
android:right="1dp" android:bottom="1dp" />
</shape>

red_box.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#1eff0000"/>
<padding android:left="1dp" android:top="1dp"
android:right="1dp" android:bottom="1dp" />
</shape>
silverburgh.meryl
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sun Feb 08, 2009 11:17 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests