[英]Dynamically change ImageButton background inside a homescreen widget
我正在開發一個Android小部件,該小部件實際上是在主屏幕上放置一個按鈕。 該按鈕使用selector
以顯示默認狀態和按下狀態。 每個州都有自己的圖像,如下面的代碼所示。
我已經有代碼來更改圖像的色調,並返回一個新的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>
代替使用硬編碼的“ @ drawable / buttonselector”,它必須是我正在生成的動態選擇器。
我發布了一個答案鏈接文本 ,我認為這與您的問題相似。 但是,這涉及兩個幾乎相似的布局。 唯一的區別是應更改的部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.