在应用程序小部件中第二次设置 imageViewResource 会隐藏我的 listView

问题描述

我有一个 listView 小部件,它在右上角包含一个按钮和一个列表视图。它还包含一个用作背景的 imageView。 关于主题的改变,我希望它改变 imageView 资源。我已经让它像这样改变了 imageView 资源:

val views = RemoteViews(context.packageName,R.layout.widget_layout)
views.setimageViewResource(R.id.imageViewBackground,R.drawable.widget_background)

这在更改主题时很顺利。但是第二次换主题的时候,imageview资源变了,但是listView没了。

这是 onReceive 方法的完整代码

    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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...