开发者

How to hide widget text on android?

I use the following code to update the text:

RemoteViews views = new Rem开发者_Go百科oteViews(context.getPackageName(), R.layout.widget);
views.setTextViewText(R.id.widget_counter, Long.toString(unreadRecordsCount));

but how can I hide it, if unreadRecordsCount = 0?


Try this:

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setTextViewText(R.id.widget_counter, Long.toString(unreadRecordsCount));
if (unreadRecordsCount == 0) {
    views.setViewVisibility(R.id.widget_counter, View.INVISIBLE);
}


I'm not totally familiar with RemoteViews but a quick check with the Android API gives this: RemoteView#setVisibility. I am assuming it works like a usual widget's setVisibility.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜