我使用以下代码更新文本:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setTextViewText(R.id.widget_counter, Long.toString(unreadRecordsCount));
但如果unreadRecordsCount = 0,我怎么能隐藏它?
答案 0 :(得分:5)
试试这个:
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);
}
答案 1 :(得分:1)
我对RemoteView
并不完全熟悉,但使用Android API进行快速检查可以得到:RemoteView#setVisibility。我假设它的工作方式与通常的widget的setVisibility类似。