Android的:如何使绘制对象选择对象、Android

2023-09-13 01:39:45 作者:B毛不烫ゞ自然卷

我觉得这是一种愚蠢的问题,但在这里我去反正。我有一个形象的按钮,我希望能够改变它的形象每次被点击。该API似乎是说,最好的方式去了解这样做是为了在包含选择和值绘制文件夹中创建XML资源。然而,当我去做出一个新的Andr​​oid XML资源,有一个为可绘制的选项。我在想什么?

I feel like this is kind of a silly question, but here I go anyways. I have an image button, and I want to be able to change it's image everytime it is clicked. The API seems to say that the best way to go about doing this is to create xml resource in the drawable folder that contains a selector and values. However when I go to make a new android xml resource, there's no option for drawables. What am I missing?

推荐答案

据我所知,Android的XML编辑器不允许创建XML可绘制。你必须去到源标签(标签:filename.xml中)手动和粘贴文本。它应该是这样的:

As far as I know, the Android XML editor doesn't allow you to create XML drawables. You have to go to the source tab (labeled: filename.xml) and paste in the text manually. It should look like:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" 
        android:drawable="@drawable/cell_top_selected" />
    <item android:drawable="@drawable/cell_top" />
</selector>