【问题标题】:Setting a StateListDrawable as ImageButton/ImageView.backgroundDrawable in a widget based on users choice in the configuration activity根据用户在配置活动中的选择,在小部件中将 StateListDrawable 设置为 ImageButton/ImageView.backgroundDrawable
【发布时间】:2011-07-04 21:05:36
【问题描述】:

我正在创建一个小部件,配置活动中的用户可以在其中选择要在按钮中使用的各种图形(ImageView(或 ImageButton)with 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>

我的问题是,如何根据用户在配置活动中的选择,在小部件中显示的 ImageButton 中设置选定的背景资源?

【问题讨论】:

    标签: android configuration widget imagebutton


    【解决方案1】:

    我会在这里回答我自己的问题。似乎无法通过代码在 RemoteViews 中设置 StateListDrawable。我的解决方案是使用引用了唯一选择器的 XML 布局(我实际上制作了一个生成器,以便我可以轻松地生成它们)。当处理大量图形元素时,这很乏味,但似乎是唯一的选择。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-06
      相关资源
      最近更新 更多