使用平板电脑时,xml背景不会改变

时间:2022-09-20 13:58:21

I have an xml that declare the button background:

我有一个声明按钮背景的xml:

<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.

在我的手机三星Nexus S(Android 4.0.3),这个xml工作完美,当我按下视图背景颜色改变。但我在平板电脑上遇到了问题(三星Galaxy标签,Android 3.2),单击按钮但我没有看到背景的任何变化。平板电脑的背景颜色永远不会改变。

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

任何人都知道为什么这只发生在平板电脑上?我该如何解决这个问题?

3 个解决方案

#1


5  

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.

我遇到了同样的问题,但我设法解决了这个问题:实际问题在于android 3.2中关于硬件加速的缺陷,所以如果你在AndroidManifest中放入你的应用程序是hardwareAccelerated =“true”你的问题将会解决。

#2


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.

并在每个布局上调用您的xml。可能是当它在平板电脑中被点击时,它没有正确显示,我曾经遇到过这个问题,因为尺寸或分辨率不匹配,所以颜色也没有正确显示。

#3


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:

尝试将.xml更改为:

<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.

你可以根据自己的喜好设置颜色。那就是你使用静态颜色。你也可以添加渐变和圆角边框。

#1


5  

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.

我遇到了同样的问题,但我设法解决了这个问题:实际问题在于android 3.2中关于硬件加速的缺陷,所以如果你在AndroidManifest中放入你的应用程序是hardwareAccelerated =“true”你的问题将会解决。

#2


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.

并在每个布局上调用您的xml。可能是当它在平板电脑中被点击时,它没有正确显示,我曾经遇到过这个问题,因为尺寸或分辨率不匹配,所以颜色也没有正确显示。

#3


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:

尝试将.xml更改为:

<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.

你可以根据自己的喜好设置颜色。那就是你使用静态颜色。你也可以添加渐变和圆角边框。