我的 appwidget-provider 在 xml 文件夹中不起作用,但在布局文件夹中起作用
My appwidget-provider doesn't work in xml folder but works in layout folder
我遇到了问题...我已经开始通过 Xamarin 学习 android 开发。
我正在尝试构建我的第一个小部件,名为 HelloWorldWidget。
我的问题是,我的 appwidget-provider xml 在 xml 文件夹中无法识别,我收到此错误:
No resource found that matches the given name (at 'resource' with value '@xml/HelloWorldWidgetProvider'). HelloWidget.Droid C:\Users\paulo\Source\Repos\Pocs\HelloWidget\HelloWidget\HelloWidget.Droid\obj\Debug\android\manifest\AndroidManifest.xml 17
当我将文件复制到布局资源并将我的资源路径更改为@layout/ 时,一切正常。
这是我的文件:
resources/xml/HelloWorldWidgetProvider.xml
<?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="86400000"
android:initialLayout="@layout/HelloWorldWidget"
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen">
</appwidget-provider>
resources/layout/HelloWorldWidget.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/HelloWorldWidgetText"
android:text="Hello World!"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
HelloWordWidget.cs
[BroadcastReceiver(Label = "@string/HelloWorldWidgetLabel")]
[IntentFilter(new string[] { "android.appwidget.action.APPWIDGET_UPDATE" })]
[MetaData("android.appwidget.provider", Resource = "@xml/HelloWorldWidgetProvider")]
public class HelloWorldWidget : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
}
}
有什么线索吗?
这总是有点棘手 ;) 您必须将其引用为小写
[MetaData("android.appwidget.provider", Resource = "@xml/helloworldwidgetprovider")]
我遇到了问题...我已经开始通过 Xamarin 学习 android 开发。
我正在尝试构建我的第一个小部件,名为 HelloWorldWidget。
我的问题是,我的 appwidget-provider xml 在 xml 文件夹中无法识别,我收到此错误:
No resource found that matches the given name (at 'resource' with value '@xml/HelloWorldWidgetProvider'). HelloWidget.Droid C:\Users\paulo\Source\Repos\Pocs\HelloWidget\HelloWidget\HelloWidget.Droid\obj\Debug\android\manifest\AndroidManifest.xml 17
当我将文件复制到布局资源并将我的资源路径更改为@layout/ 时,一切正常。
这是我的文件:
resources/xml/HelloWorldWidgetProvider.xml
<?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="86400000"
android:initialLayout="@layout/HelloWorldWidget"
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen">
</appwidget-provider>
resources/layout/HelloWorldWidget.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/HelloWorldWidgetText"
android:text="Hello World!"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
HelloWordWidget.cs
[BroadcastReceiver(Label = "@string/HelloWorldWidgetLabel")]
[IntentFilter(new string[] { "android.appwidget.action.APPWIDGET_UPDATE" })]
[MetaData("android.appwidget.provider", Resource = "@xml/HelloWorldWidgetProvider")]
public class HelloWorldWidget : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
}
}
有什么线索吗?
这总是有点棘手 ;) 您必须将其引用为小写
[MetaData("android.appwidget.provider", Resource = "@xml/helloworldwidgetprovider")]