问题描述
我正在用 Mono 为 Android 构建一个对话框,如下所示:
AlertDialog.Builder builder = new AlertDialog.Builder(Context);builder.SetTitle(Context.GetString(Resource.String.MyTitle));builder.SetMessage(Context.GetString(Resource.String.MyQuestion);//是的,不行builder.SetPositiveButton(Android.Resource.String.Yes, new EventHandler((dlgSender, dlgEvt) => { doSomething();});builder.SetNegativeButton(Context.GetString(Android.Resource.String.No), new EventHandler((dlgSender, dlgEvt) => { doSomethingElse();}));builder.SetNeutralButton(Context.GetString(Android.Resource.String.Cancel),new EventHandler((dlgSender, dlgEvt) => {}));对话框对话框 = builder.Create();dialog.Show();
这会通过三个按钮提出我的问题:取消,取消,确定",而我希望得到不,取消,是".我上面的代码有什么问题吗,或者这里的 Android 版 Mono 有什么问题?
android.R.string.yes
和 android.R.string.no
(用作 Android.Resource.String.*
in Monodroid) 只是资源名称,相当于OK"和Cancel".您必须制作自己的字符串资源.
来自 Android 的 strings.xml
(Android 4.2):
<!-- 偏好框架字符串.--><string name="ok">OK</string><!-- 偏好框架字符串.--><string name="cancel">取消</string><!-- 偏好框架字符串.--><string name="yes">OK</string><!-- 偏好框架字符串.--><string name="no">取消</string>
I am building a dialog in Mono for Android like this:
AlertDialog.Builder builder = new AlertDialog.Builder(Context);
builder.SetTitle(Context.GetString(Resource.String.MyTitle));
builder.SetMessage(Context.GetString(Resource.String.MyQuestion);
//YES, not OK
builder.SetPositiveButton(Android.Resource.String.Yes, new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) => { doSomething();});
builder.SetNegativeButton(Context.GetString(Android.Resource.String.No), new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) => { doSomethingElse();}));
builder.SetNeutralButton(Context.GetString(Android.Resource.String.Cancel),
new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) => {}));
Dialog dialog = builder.Create();
dialog.Show();
This brings up my question with three buttons: "Cancel, Cancel, Ok" whereas I expected to get "No, Cancel, Yes". Is anything wrong with my code above or is there something wrong with Mono for Android here?
android.R.string.yes
and android.R.string.no
(used as Android.Resource.String.*
in Monodroid) are just resource names, which equate to "OK" and "Cancel". You'll have to make your own string resources.
From Android's strings.xml
(Android 4.2):
这篇关于使用 Android 资源字符串的错误是/否文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!