【发布时间】:2018-05-19 06:48:32
【问题描述】:
我以前是这样创建的
AlertDialog.Builder b = new AlertDialog.Builder( Forms.Context );
而且效果很好。但是 Forms.Context 现在已经过时了,所以我把它改成了
AlertDialog.Builder b = new AlertDialog.Builder( Android.App.Application.Context );
现在它崩溃了
Android.Content.Res.Resources+NotFoundException: Resource ID #0x0
我尝试了替代构造函数
AlertDialog.Builder b = new AlertDialog.Builder( Android.App.Application.Context, Resource.Style.Theme_AppCompat_Light );
然后崩溃了
Android.Views.WindowManagerBadTokenException: Unable to add window -- token null is not for an application
那么我在 XF2.5 中将什么上下文传递给 AlertDialog.Builder()?我不想为此安装第 3 方库。
【问题讨论】:
-
尝试传入你的 MainActivity
标签: xamarin xamarin.forms android-alertdialog android-context