如何在Xamarin中使用Activity属性android:showForAllUsers? [英] How to use Activity attribute android:showForAllUsers in Xamarin?
问题描述
该属性未在Xamarin中实现.这意味着我不能像应有的那样将其声明为我的Activity类的属性:
The attribute is not implemented in Xamarin. This mean I can't declare it as an attribute of my Activity Class like it should:
[Activity(Label = "@string/app_name", Theme = "@style/MainTheme.StopAlarm", LaunchMode = Android.Content.PM.LaunchMode.SingleTask, ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, NoHistory = true)]
public class StopAlarmActivity : Activity
{
...
}
没有ShowForAllUsers选项.
There's no ShowForAllUsers option.
另一种选择是编辑Properties => AndroidManifest.xml并手动添加活动,如下所示:
The other option is to edit Properties => AndroidManifest.xml and add the activity manually like this:
<activity
android:name=".StopAlarmActivity"
android:label="@string/app_name"
android:theme="@style/MainTheme.StopAlarm"
android:showForAllUsers="true">
</activity>
但是一旦我编译了最后的AndroidManifest.xml文件,它包含两个声明,即手动添加的和从类声明中编译的一个.
But once I compile the final AndroidManifest.xml file contains two declarations, the manually added and the compiled one from the class declaration.
<activity android:name=".StopAlarmActivity" android:label="@string/app_name" android:theme="@style/MainTheme.StopAlarm" android:showForAllUsers="true"></activity>
<activity android:label="@string/app_name" android:launchMode="singleTask" android:noHistory="true" android:screenOrientation="portrait" android:theme="@style/MainTheme.StopAlarm" android:name="md5e24228758d0205525e724fe958bff865.StopAlarmActivity" />
也就是说,似乎唯一的选择是在每次编译后编辑已编译的AndroidManifest.xml文件.这是对问题的重大突破.
That said, it looks like the only option is to edit the compiled AndroidManifest.xml file after each compilation. Which is a major breach for problems.
在不需要每次编译应用程序时都依赖于记住它的任何其他方式来实现它吗?
Any other way to accomplish it where I don't need to rely on remembering it every time I compile the app?
推荐答案
在您的Activity
属性上,应用Name
以避免基于MD5的Java类自动命名:
On your Activity
attribute, applied a Name
to avoid the MD5-based Java class auto-naming:
[Activity(Name = "com.sushihangover.MainActivity")]
在清单中使用与您希望应用于此活动的属性相同的完全限定名称(无缩写点符号):
In your manifest use the same fully-qualified name (no abbreviated dot notation) with the attributes you wish to apply to this activity:
<activity
android:name="com.sushihangover.MainActivity"
android:showForAllUsers="true"
android:icon="@mipmap/icon"
android:label="MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
注意:此Activity的所有属性都需要添加到清单中,而不是Activity类的属性中.
Note: All the attributes for this Activity need to be added within the manifest, not the Activity class attribute.
最终的清单条目将正确合并:
The final manifest entries will be merged correctly:
<activity android:name="com.sushihangover.MainActivity" android:showForAllUsers="true" android:icon="@mipmap/icon" android:label="MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这篇关于如何在Xamarin中使用Activity属性android:showForAllUsers?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!