Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xml background don't change when i use tablet

I have an xml that declare the button background:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/selector_pressed" />
    <item android:state_focused="true" android:drawable="@color/selector_focused" />
    <item android:drawable="@android:color/transparent" />
</selector>

On my phone Samsung Nexus S (android 4.0.3) , this xml work perfectly, when i press the view the background color change. But I got a problem on tablets (Samsung Galaxy tab, Android 3.2), the button is clicked but i don't see any changes for the backgroung. The background color never change for tablets.

Any one have an idea why this happening only for tablets? and how can i fix this?

like image 406
haythem souissi Avatar asked Feb 01 '13 10:02

haythem souissi


3 Answers

I've had the same problem but I've managed to solve this: the actual problem lies in a defect in android 3.2 regarding hardware acceleration so if you put in your AndroidManifest that your application is hardwareAccelerated="true" your problem will be solved.

like image 53
vanleeuwenbram Avatar answered Nov 13 '22 09:11

vanleeuwenbram


I would suggest you to adjust your layout on each layout folder

  • layout
  • layout-800x480
  • layout-land
  • etc. refer here http://developer.android.com/guide/practices/screens_support.html

and call your xml on each layout. It could be that when it was clicked in tablet, it was not displayed properly, I once experienced that issue too because the dimension or the resolution did not match, so the color is not displaying properly as well.

like image 2
She Smile GM Avatar answered Nov 13 '22 09:11

She Smile GM


try getting rid of the

<item android:state_focused="true" android:drawable="@color/selector_focused" />

could just be the way that version of OS intercepts pressed and focused. just a guess tho, didn't really test it.

Try changing your .xml to:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>         
            <solid
                android:color="#11223344" />
        </shape>
    </item>
    <item>
        <shape>
           <solid
               android:color="#AABBCCDD" />
        </shape>
    </item>
</selector>

of coures you can set your color to anything you'd like. That is if you are using static colors. you could add gradients and rounded edges and a border to this too.

like image 1
Konrad Winkowski Avatar answered Nov 13 '22 09:11

Konrad Winkowski