代码之家  ›  专栏  ›  技术社区  ›  Colin O'Dell

动态更改主屏幕小部件中的ImageButton背景

  •  1
  • Colin O'Dell  · 技术社区  · 15 年前

    selector 以显示默认状态和按下状态。每个州都有自己的映像,如下面的代码所示。

    change the hue of an image 并返回一个新的StateListDrawable以在ImageButton中使用。

    我的问题 :如何实际将StateListDrawable应用于ImageButton的 android:background

    以下是小部件布局的XML源:

    <LinearLayout
        android:id="@+id/LinearLayout01"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        <ImageButton
            android:id="@+id/ImageButton01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:background="@drawable/buttonselector" />
    </LinearLayout>
    

    与其使用硬编码的“@drawable/buttonselector”,不如使用我正在生成的动态选择器。

    1 回复  |  直到 15 年前
        1
  •  0
  •   Community Mohan Dere    9 年前

    我已经发布了一个答案 link text