我正在创建一个小部件,配置 Activity 中的用户可以在其中选择要在按钮(ImageView(或 ImageButton)和 StateListDrawable)中使用的各种图形。添加小部件时,所选图形将用于小部件布局。布局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:id="@+id/button"
android:layout_width="72dip"
android:layout_height="72dip"
android:background="@null"
android:clickable="true">
</ImageView>
</LinearLayout>
我的问题是,如何根据用户在配置 Activity 中的选择,在小部件中显示的 ImageButton 中设置选定的 backgroundResource?
最佳答案
我会在这里回答我自己的问题。似乎无法通过代码在 RemoteViews 中设置 StateListDrawable。我的解决方案是使用引用唯一选择器的 XML 布局(我实际上制作了一个生成器,以便我可以轻松生成它们)。当处理大量图形元素时,这很乏味,但似乎是唯一的选择。
关于android - 根据用户在配置 Activity 中的选择,在小部件中将 StateListDrawable 设置为 ImageButton/ImageView.backgroundDrawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5127280/