我有一个在两个图像之间切换的窗口小部件,每次用户点击它时窗口小部件都会更改 所以我为这个小部件定义了一个布局,如下所示
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/parrotstate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:clickable="true"
android:src="@drawable/widget_awake" />
</RelativeLayout>
在AppWidgetProvide class
中,我需要读取属性android:src以了解设置了哪个图像。
通常我在Activity类中使用findViewById
,但这里是AppWidgetProvide class
答案 0 :(得分:0)
可能这个问题是重复尝试使用这篇文章:How to find view id in appwidgetprovider?
使用构造函数,您可以获得Remoteview:
RemoteViews(String packageName, int layoutId)
//Create a new RemoteViews object that will display the views contained in the specified layout file.
apply返回视图
apply(Context context, ViewGroup parent)
//Inflates the view hierarchy represented by this object and applies all of the actions.
link:http://developer.android.com/reference/android/widget/RemoteViews.html