在其他资源中包含资源文件

时间:2013-10-17 12:25:34

标签: android

使用案例

如果您要设计多个按钮,并且希望其中包含不同的图像和背景渐变。

我现在拥有的

ImageButton,背景如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" >
    <layer-list>
        <item>
            <shape android:shape="rectangle">
                <gradient
                    android:type="linear"
                    android:startColor="@color/green_yellow"
                    android:endColor="@color/green_mantis" />

            </shape>
        </item>
        <item>
            <bitmap
                android:antialias="true"
                android:gravity="center"
                android:src="@drawable/more_button_check_rates_img"/>
        </item>
    </layer-list>
</item>
</selector>

这是有效的,但现在我想要另一个带有其他位图。

问题 我可以创建三个文件(1个形状和两个按钮),然后将形状包含在两个按钮中。

类似的东西:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" >
    <layer-list>
        <include shape="background"> <!-- this line -->
        <item>
            <bitmap
                android:antialias="true"
                android:gravity="center"
                android:src="@drawable/more_button_check_rates_img"/>
        </item>
    </layer-list>
</item>
</selector>

1 个答案:

答案 0 :(得分:0)

是的,您必须为多个背景按钮创建多个xml,并在这些按钮上设置该xml。))

相关问题