简体   繁体   中英

Android: change widget background

is it possible to change widget bg without using imageview?

With image i change the bg like this:

RemoteViews updateViews = new RemoteViews(EditPreferences.this.getPackageName(), R.layout.main);
updateViews.setImageViewResource(R.id.ImageView01, R.drawable.blacktrans);          
ComponentName thisWidget = new ComponentName(EditPreferences.this, HelloWidget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(EditPreferences.this);
manager.updateAppWidget(thisWidget, updateViews);

What if i am not using an imageview but setting the background of the relative layout?

     android:background="@drawable/blacktrans320x100"

Is it possible? I haven't found anything on google.

Citing CommonsWare from another topic:

You cannot modify the background that way, due to limitations in the RemoteViews API.

What you can do is choose a different layout -- one with the background you want -- when you create your RemoteViews instance for this particular update.

Android: Changing LinearLayout in a widget

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM