简体   繁体   English

应用小部件未显示在Oreo上

[英]App widget not displaying on Oreo

Instead, the widget area displays an error message saying "Problem while loading widget" 而是,小部件区域显示一条错误消息,提示“加载小部件时出现问题”

In the log, I see these errors when adding the app widget : 在日志中,添加应用小部件时会看到以下错误:

07-24 15:57:24.651 2057-5433/? E/RemoteViews: Package name com.theapp not found

07-24 15:57:24.651 2057-2057/? W/AppWidgetHostView: updateAppWidget couldn't find any view, using error view
    android.content.res.Resources$NotFoundException: Resource ID #0x7f0b0034 type #0x5 is not valid
        at android.content.res.Resources.loadXmlResourceParser(Resources.java:2139)
        at android.content.res.Resources.getLayout(Resources.java:1143)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
        at android.widget.RemoteViews.inflateView(RemoteViews.java:3498)
        at android.widget.RemoteViews.-wrap1(Unknown Source:0)
        at android.widget.RemoteViews$AsyncApplyTask.doInBackground(RemoteViews.java:3600)
        at android.widget.RemoteViews$AsyncApplyTask.doInBackground(RemoteViews.java:3596)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)

The widget displays fine on Android versions pre 8 在Android 8之前的版本中,该小部件显示良好

EDIT: Here is my widget layout file: 编辑:这是我的小部件布局文件:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/widget_margin">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/appwidget_background"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/button_settings"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="@string/app_name" />

        <TextView
            android:id="@+id/button_on"
            android:layout_width="56dp"
            android:layout_height="match_parent"
            android:text="@string/on" />

        <TextView
            android:id="@+id/button_off"
            android:layout_width="56dp"
            android:layout_height="match_parent"
            android:text="@string/off" />
    </LinearLayout>
</FrameLayout>

and meta data file: 和元数据文件:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="40dp"
    android:minHeight="40dp"
    android:updatePeriodMillis="0"
    android:previewImage="@drawable/widget_preview"
    android:configure="com.theapp.appwidget.AppWidgetActivity"
    android:initialLayout="@layout/appwidget"
    android:resizeMode="horizontal|vertical" />

"Problem while loading widget" + your limited stacktrace indicate a layout problem. “加载窗口小部件时出现问题” +有限的堆栈跟踪指示布局问题。 It would help if you showed your layout file. 如果您显示布局文件,这将有所帮助。 Go back and check all your attributes, images and views. 返回并检查所有属性,图像和视图。 There may be an element to your layout that isn't allowed for an appwidget as they are restricted in what views can be used. 您的版式中可能有一个元素不允许应用程序使用,因为它们限制了可以使用哪些视图。 Also check that you sized your widget properly in the metadata xml file, and check that your padding follows the guidelines. 还要检查您是否在元数据xml文件中正确设置了窗口小部件的大小,并检查填充是否遵循准则。 The android guideline describes how you should size it and use padding: https://developer.android.com/guide/practices/ui_guidelines/widget_design android准则描述了如何调整其大小并使用填充: https : //developer.android.com/guide/practices/ui_guidelines/widget_design

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM