android - 我的小部件背景消失了 - android

标签 android android-widget

我开发了一个带有小部件的 Android 应用程序。除了一台移动设备 Samsung galaxy grand,android 4.1.2 之外,该小部件运行良好。小部件的背景可绘制消失,而文本仍然可见。我不知道问题是否出在设备上,但我注意到此设备上的其他小部件没有此问题。当我按住小部件将其删除时,背景出现,然后再次消失。我已经在具有相同 API 的其他设备上测试了该小部件,并且运行良好。

关于原因有什么建议吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dip"
android:background="@drawable/dthree"
android:orientation="vertical"
android:weightSum="1.0" 
>

<TextView
    android:id="@+id/widgetDateTV"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="15dp"
    android:layout_weight="0.1"
    android:gravity="center"
    android:textAlignment="center"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="@color/OLIVE" />

<TextView
    android:id="@+id/widgetTextTV"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center|center_vertical"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="5dp"
    android:layout_weight="0.9"
    android:gravity="center|center_vertical"
    android:textAlignment="center"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="@color/BROWN" 
    />  

ComponentName thisWidget = new ComponentName(context,
                MyWidgetProvider.class);
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
        for (int widgetId : allWidgetIds) {



RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                        R.layout.widget_layout);

remoteViews.setInt(widgetId, "setBackground", R.drawable.dthree);
                remoteViews.setTextViewText(R.id.widgetTextTV, "some text");
                remoteViews.setTextViewText(R.id.widgetDateTV,"date");


            Intent intent = new Intent(context, DummyActivity.class);

            intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,appWidgetIds);

            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                    intent, PendingIntent.FLAG_UPDATE_CURRENT);
            remoteViews.setOnClickPendingIntent(R.id.widgetTextTV,
                    pendingIntent);
            appWidgetManager.updateAppWidget(widgetId, remoteViews);}

最佳答案

我通过提供 ldpi、mdpi 密度解决了这个问题。我在 drawable 文件夹中使用了一张图片。

关于android - 我的小部件背景消失了 - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22061919/

相关文章:

java - 如何访问 com.android.internal.telephony.CallManager?

android - 无法为 opencv android 加载信息库

android - 某些表的动态数据库备份

java - 如何从不扩展 Activity 的类创建 DatePicker,Android?

android - 如何在android中使用XML布局在 ImageView 中为图像制作圆角

android - 如何更改 android spinner popupBackground

android - USB调试: How to revoke the "Always allow from this computer" option

android - Android:使用OpenCV对齐图像

android - 滚动ListView后,ListView View 底部的按钮收不到事件

android - 远程 TextView 不支持 setTextSize(float)?