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 RemoteView
s but a quick check with the Android API gives this: RemoteView#setVisibility. I am assuming it works like a usual widget's setVisibility.
精彩评论