安卓更改窗口小部件的背景图片部件、背景图片、窗口

2023-09-05 00:33:54 作者:云深不知处

一直在努力,在过去两天改变我的窗口小部件的背景下,基于一些if语句(去掉,现在只是想改变窗口小部件的背景从类)下面是我下面的源代码。这是怎么回事,虽然,我以前细如改变图像作为背景,但无法得到它的工作为我的小部件谢谢。这是我最近一次尝试的方式。

  //控件提供程序类
公共类WidgetProvider扩展AppWidgetProvider {

    公共无效的OnUpdate(上下文的背景下,AppWidgetManager appWidgetManager,INT [] appWidgetIds){
        最终诠释N = appWidgetIds.length;

        的for(int i = 0; I&n种;我++){
            INT appWidgetId = appWidgetIds [I]

            意向意图=新的意图(背景下,com.widget.WidgetDialog.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(上下文,0,意图,0);

            RemoteViews意见=新RemoteViews(context.getPackageName(),R.layout.widget);
            views.setOnClickPendingIntent(R.id.widget,pendingIntent);

            appWidgetManager.updateAppWidget(appWidgetId,意见);
            views.setImageViewBitmap(R.id.widget,((BitmapDrawable)context.getResources()getDrawable(R.drawable.widget_background))getBitmap());

        }
    }
}



//窗口小部件布局XML
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >
    <按钮机器人:ID =@ + ID /小工具
    机器人:后台=#00000000
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    < /按钮>
< / LinearLayout中>
 

解决方案

任何人有任何其他的想法?真的希望得到这个想通了

编辑:结束了设置不同的布局,目前有10个不同的布局2不同的部件,但效率不高的工作更多的是黑客的身边真的

Been struggling for the past two days to change the background of my widget, based on some if statements (removed right now just want to change the widget background from the class) here is my source below. What's up though, I've changed images before fine such as backgrounds but can not get it to work for my widget thank you. This is my most recent attempt by the way

//Widget Provider Class
public class WidgetProvider extends AppWidgetProvider {

    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        final int N = appWidgetIds.length;

        for (int i=0; i<N; i++) {
            int appWidgetId = appWidgetIds[i];

            Intent intent = new Intent(context, com.widget.WidgetDialog.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
            views.setOnClickPendingIntent(R.id.widget, pendingIntent);

            appWidgetManager.updateAppWidget(appWidgetId, views);
            views.setImageViewBitmap(R.id.widget, ((BitmapDrawable)context.getResources().getDrawable(R.drawable.widget_background)).getBitmap());

        }
    }
}



//Widget Layout XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button android:id="@+id/widget"
    android:background="#00000000"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    </Button>
</LinearLayout>
怎样更改WINDOWS7的窗口背景 有图

解决方案

Anyone got any other ideas? Really would like to get this figured out

Edit: ended up setting up different layouts currently have 10 different layouts for 2 different widgets inefficient but working more of a hack around really