问题描述
我有一个 listView 小部件,它在右上角包含一个按钮和一个列表视图。它还包含一个用作背景的 imageView。 关于主题的改变,我希望它改变 imageView 资源。我已经让它像这样改变了 imageView 资源:
val views = RemoteViews(context.packageName,R.layout.widget_layout)
views.setimageViewResource(R.id.imageViewBackground,R.drawable.widget_background)
这在更改主题时很顺利。但是第二次换主题的时候,imageview资源变了,但是listView没了。
override fun onReceive(context: Context,intent: Intent) {
if (intent.action == "android.appwidget.action.APPWIDGET_UPDATE_OPTIONS") {
val views = RemoteViews(context.packageName,R.layout.widget_layout)
val mode = context.resources.configuration.uiMode.and(Configuration.UI_MODE_NIGHT_MASK)
when (mode) {
Configuration.UI_MODE_NIGHT_YES -> {
Toast.makeText(context,"Going into night mode",Toast.LENGTH_SHORT).show()
views.setimageViewResource(R.id.imageViewBackground,R.drawable.widget_background_night)
}
Configuration.UI_MODE_NIGHT_NO -> {
Toast.makeText(context,"Going into light mode",R.drawable.widget_background)
}
Configuration.UI_MODE_NIGHT_UNDEFINED -> {
}
}
val mManager = AppWidgetManager.getInstance(context)
mManager.updateAppWidget(ComponentName(context,FirstMoneyWidgetProvider::class.java),views)
}
}
widget_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageViewBackground"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/widget_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:divider="@android:color/transparent" />
<ImageButton .../>
</RelativeLayout>
为什么多次更改图像视图资源时listView没有出现?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)