【问题标题】:setTextviewText() method of RemoteView class not setting any textRemoteView 类的 setTextviewText() 方法未设置任何文本
【发布时间】:2017-02-03 12:16:05
【问题描述】:

我在应用程序小部件中使用 GridView。我想在小部件中的每个图像下方显示图像和文本。图像(应用程序图标)正在显示;但是没有显示文本。我正在使用 setTextViewText() 来设置文本。

WidgetViewsFactory.java 类的getViewAt()方法:

public RemoteViews getViewAt(int position)  {

    RemoteViews row = new RemoteViews(mContext.getPackageName(), R.layout.widget_list_row);

    ApplicationInfo data = null;
    Bundle extras = new Bundle();
    Intent fillInIntent = new Intent(mContext, NotificationReceiverIntent.class);
    PendingIntent pendingLaunchIntent;
    try {
        packageName = appsPackageNameList.get(position).split(";;");
        data = packageManager
                .getApplicationInfo(packageName[0], 0);

        if (null != data) {
            Bitmap icon = CommonCode.getBitmapFromIcon(data.loadIcon(packageManager));
            row.setImageViewBitmap(R.id.img_widget, icon);
            Log.e("count", packageName[1]);
            row.setTextViewText(R.id.txt_notification_count, packageName[1]); //setting text
        }

    } catch (final PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return (row);
}

我正在打印给我正确值的文本(数组值)。 那么我应该怎么做才能在我的小部件中设置文本呢?

【问题讨论】:

    标签: android gridview widget


    【解决方案1】:

    我在深入研究我的代码后得到了答案。 TextView 的默认颜色在小部件中是白色的,所以我只是更改了 我的文本颜色从 xml 变为黑色,它起作用了!!

    【讨论】:

      【解决方案2】:

      最后添加文本,你必须使用

      appWidgetManager.updateAppWidget(appWidgetId, row);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-10
        • 1970-01-01
        • 1970-01-01
        • 2010-10-20
        相关资源
        最近更新 更多