xml background don't change when i use tablet
Asked Answered
G

4

8

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?

Gordongordy answered 1/2, 2013 at 10:42 Comment(9)
i tried those solutios: #11661690 No one worked for me :(Gordongordy
Have you tried with image file drawables instead of defining colours? I would check that, and if it works, you will have a workaround, at least.Magma
yes i tried that but doesn't work :(Gordongordy
It seems like a bug, doesn't it? So sadly you will have to take the annoying path of doing it through Java code...Magma
Have you tried to press the button (and nothing happens), and then change to any other other activity and then come back? So you will be forcing the layout to be repainted and see if the selector is not working or is a refreshing problem....Magma
Sorry, the answer I posted and removed was for a listview... I can answer your question later, but what I wrote does not pertain to your problem (and your comment in that other thread, nor that other thread pertains to your problem).Louis
can you please explain to me why , i am encountring this problem? And can we fix that, i tried for two day to find a solution but i failed :(Gordongordy
Please show us the XML for the button and also your colors. By click I assume you mean you mean user click, not click from code, correct? Also you don't want it to stay pressed right, just show a different color when you press it?Louis
Have you tried to add this to folder res/color instead of res/drawable? You have to change android:drawable to android:color.Mamey
D
6

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.

Dialyse answered 19/2, 2013 at 9:42 Comment(6)
thanks thanks, i got t a message, You may award your bounty in 1 hour.Gordongordy
Are you saying the issue will be fixed if we have that value or if we remove it? I currently have that value set, but I'm getting this issue.Oleoresin
if we havd this value you have to add android:hardwareAccelerated="true" to applicationGordongordy
this fixed my problem, i guess maybe we don't have the same issu :(Gordongordy
Try changing inside the library code the manageLayers method to check if maybe somewhere else the hardware acceleration is disabled for some reason (might be on the device)Dialyse
Your answer solved my problem.can you explain more details about hardwareAccelerated="true"Deettadeeyn
R
2

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

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.

Resistor answered 5/2, 2013 at 1:53 Comment(0)
D
1

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.

Disinterested answered 6/2, 2013 at 17:17 Comment(2)
i did it,with the default selector i still have the problem. Everythink work ok on my device but not in my tabletGordongordy
are your drawables just colors? or is it a image that you are loding ? i'm assuming that since you are calling @color that they are just a color ref if so try my update to original post..Disinterested
H
0

I used :

android:hardwareAccelerated="false"  in AndroidManifest.xml <application> tag

it's working with very fine

Hit answered 24/9, 2018 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.