我目前在一個類庫(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的情況下將主題添加到類庫項目中?