【问题标题】:Change properties of view inside RemoteView在 RemoteView 中更改视图的属性
【发布时间】:2017-06-07 16:01:15
【问题描述】:

我有一个具有TextView 的应用小部件,我需要更改 textColorshadowColorgravity

虽然我可以轻松地将带有 view.settextColor() 的 textColor 和带有 view.setInt(); 的 Gravity 设置到 RemoteView,但我找不到设置 shadowColor 的方法。

阴影的颜色取决于所选文本的颜色(仅黑底黑字或黑底白字),并且它是易读性所必需的。

我尝试使用已经设置的文本和阴影颜色来膨胀不同的布局并且它起作用了,但是小部件的定义 XML 需要声明一个初始布局,并且我最终会为其 textViews 获得两个相同的 id,所以我不'不知道我是否应该。

如果我不能以编程方式设置它,我还剩下哪些选项?

谢谢。

【问题讨论】:

  • 你有运气吗? setShadowColor 或某事。像这样在 2021 年似乎仍然不受支持...

标签: java android remoteview


【解决方案1】:
public Bitmap buildUpdate(String time) 
{
   Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444);
   Canvas myCanvas = new Canvas(myBitmap);
   Paint paint = new Paint();       
   paint.setAntiAlias(true);
   paint.setSubpixelText(true);       
   paint.setStyle(Paint.Style.FILL);
   paint.setColor(Color.WHITE);
   paint.setTextSize(65);
   paint.setTextAlign(Align.CENTER);
   myCanvas.drawText(time, 80, 60, paint);
   return myBitmap;

}

String time = (String) DateFormat.format(mTimeFormat, mCalendar);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.main);
views.setImageViewBitmap(R.id.TimeView, buildUpdate(time));

来源:How to use a custom typeface in a widget?

【讨论】:

    猜你喜欢
    • 2012-05-28
    • 2017-09-07
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 2023-03-23
    相关资源
    最近更新 更多