AssemblyInfo主题,类库(Android)Xamarin
问题描述:
我目前在一个类库(Android)项目中工作。 该项目设想与其他多个项目一起工作,因此无法事先知道每个主项目可能具有哪个主题。 但是,我打算使用v7.AlertDialog,它在清单的应用程序标记上没有使用Theme.AppCompat时不起作用,但没有用于类库(Android)的Manifest。AssemblyInfo主题,类库(Android)Xamarin
我通过使用assemblyinfo.cs文件请求权限和功能,从而取得了成功。现在,我想添加以下内容:
[assembly: Application(Theme = "@android:style/Theme.AppCompat.Light")]
但是这个代码运行时失败:
AlertDialog7.Builder builder = new AlertDialog7.Builder(this);
AlertDialog7 alert = builder.Create();
alert.Show();
输出: 未处理的异常:Java.Lang.IllegalStateException:您需要使用一个主题。 AppCompat主题(或后代)与此活动。
如果我添加此到应用程序标签,然后在项目运行没有任何问题:
android:theme="@style/Theme.AppCompat.Light"
我已尝试添加主题到AlertDialog这也失败:
AlertDialog7.Builder builder = new AlertDialog7.Builder(this, <THEME>);
也试过添加到也失败的活动标签:
[Activity(Theme = <THEME>)]
问题:我该如何确保类库(Android)能够独立于主项目主题而正常工作,并且如何在不使用主项目Manifest的情况下将主题添加到类库项目中?
答
花了数小时后,我终于在发布问题后得到了一个解决方案。
我只是从这个改变:
[assembly: Application(Theme = "@android:style/Theme.AppCompat.Light")]
要这样:
[assembly: Application(Theme = "@style/Theme.AppCompat.Light")]