我目前正在一个类库(Android)项目中工作。这个项目应该与多个其他项目一起工作,因此无法预先知道每个主项目可能有哪个主题。但是,我打算使用v7.AlertDialog,它在清单的应用程序标记上没有Theme.AppCompat就不能工作,但是没有类库(Android)的manifest。
通过使用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:您需要在此活动中使用Theme.AppCompat主题(或后代)。
如果我将其添加到应用程序标记中,则项目运行时不会出现任何问题:
android:theme="@style/Theme.AppCompat.Light"我尝试将主题添加到AlertDialog中,但也失败了:
AlertDialog7.Builder builder = new AlertDialog7.Builder(this, <THEME>);还试图添加到也失败的活动标记中:
[Activity(Theme = <THEME>)]问:如何确保类库(Android)独立于主项目主题正常工作,以及如何在不使用主项目声明的情况下将主题添加到类库项目中?
发布于 2017-04-26 11:08:21
在这个问题上花了几个小时之后,我终于得到了一个解决办法。
我只是改变了这一点:
[assembly: Application(Theme = "@android:style/Theme.AppCompat.Light")]对此:
[assembly: Application(Theme = "@style/Theme.AppCompat.Light")]https://stackoverflow.com/questions/43632190
复制相似问题