我的插件的佈局文件開始在頂層有:設置AppWidget背景一個小部件影響其他太
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin"
android:id="@+id/widget"
android:background="#20000000" >
所以,起始背景是半透明的。然後,在執行過程中的某個時刻,我呼籲以下,以使背景完全透明:
remoteViews.setInt(R.id.widget, "setBackgroundColor", Color.parseColor("#00000000"));
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
雖然這個作品,就是我的發現是,在添加其他小部件,該插件的背景開始起飛根據佈局xml完全透明而不是半透明。就好像爲一個小部件設置背景顏色已經改變了所有的部分,包括隨後添加的新小部件。
現在,這是奇怪的,因爲在同一時間,上面的代碼中,我還添加了位圖到小工具(通過RemoteViews
)有:
remoteViews.setImageViewBitmap(R.id.imageView, bmp);
...和是位圖沒有按將不會出現在所有後續的小部件中,因此我使用的基本方法似乎很有用。
那麼爲什麼背景傳播到其他小部件?
EDIT添加的appWidgetId
推導作爲評論請求:
基本上來自一個Intent
,例如在該插件的配置Activity
的onCreate()
:
Intent intent = getIntent();
Bundle extras = intent.getExtras();
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
你能向我們展示如何創建這個小部件,以及如何添加新的元素? – csenga
你在哪裏添加'remoteViews.setImageViewBitmap(R.id.imageView,bmp);'? –