机器人绘制选择器的兼容性问题 [英] android drawable selector compatibility issue

查看:229
本文介绍了机器人绘制选择器的兼容性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,可绘制选择设置为背景。

I had a button with a drawable selector set as its background.

button_sign_in_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/button_sign_in_background_selected" android:state_focused="true" />
<item android:drawable="@drawable/button_sign_in_background_selected" android:state_pressed="true" />
<item android:drawable="@drawable/button_sign_in_background_selected" android:state_selected="true" />
<item android:drawable="@drawable/button_sign_in_background_normal" />

</selector>

button_sign_in_background_normal.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:visible="true">

<corners android:radius="@dimen/abc_control_corner_material" />
<solid android:color="@color/color_primary" />
</shape>

button_sign_background_selected.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners android:radius="@dimen/abc_control_corner_material" />
<solid android:color="@color/color_primary_dark" />
</shape>

我两个不同的设备,其中一个API测试21,另一个是10 API背景 button_sign_in_background.xml 不能在API 10显示,但它的工作原理API 21设备。

I tested in two different devices, one with API 21 and another is API 10. The background button_sign_in_background.xml can't show in API 10, but it works in API 21 device.

如果我直接用颜色 button_sign_in_background.xml 如下,这两种设备的工作。但是,这不是我所需要的效果,我要的是一个小半径角落环绕的按钮。

If I use color directly in button_sign_in_background.xml as following, both devices work. But this is not the effect I need, what I want is a small radius corner surround the button.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@color/color_primary_dark" android:state_focused="true" />
<item android:drawable="@color/color_primary_dark" android:state_pressed="true" />
<item android:drawable="@color/color_primary_dark" android:state_selected="true" />
<item android:drawable="@color/color_primary" />

</selector>

时,在旧的Andr​​oid设备的兼容性问题?

Is that a compatibility problem in old android device?

我该如何解决呢?任何一种意见,并回答都欢迎。

How can i solve it? Any kind of comment and answer are welcomed.

推荐答案

我用下面的code,以解决兼容性问题。只有API等级10(2.3.3 Android版)测试。演出结束后的后台手工绘制,它工作正常。如果有更多的版本有这个兼容性问题,意见都欢迎。

I use the following code to solve the compatibility issue. Only tested with API level 10 (Android 2.3.3). After show the background drawable manually, it works fine. If there are more versions have this compatibility issue, comment will be welcomed.

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {

        mEmailSignInButton.setBackgroundDrawable(
                getResources().getDrawable(R.drawable.button_sign_in_background));
    }

这篇关于机器人绘制选择器的兼容性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆