2010-10-29 81 views
1

我正在開發一個基本上在主屏幕上放置按鈕的Android小部件。該按鈕使用selector以顯示默認狀態和按下狀態。每個州都有自己的形象,您會在下面的代碼中看到。動態更改主屏幕小部件中的ImageButton背景

我已經有代碼change the hue of an image並返回一個新的StateListDrawable在ImageButton中使用。

我的問題:我該如何使用RemoteView實際將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> 

而不是使用硬編碼「@繪製/按鈕選擇器」,它需要是動態選擇我生成。

+0

我認爲這可能涉及創建一個新的StateListDrawable:http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html – 2010-10-29 16:08:16

回答

0

我已發佈回答link text,我認爲它與您的問題類似。然而,這涉及兩個幾乎相似的佈局。唯一的區別是應該改變的部分。