當應用程式語言以 Xamarin 形式轉換為越南語時,如何在 Android 的 DatePickerDialog 和 IOS 的 DatePicker 中以越南語顯示月份和日期
安卓:
protected override DatePickerDialog CreateDatePickerDialog(int year, int month, int day)
{
pickerDialog = new DatePickerDialog(Context, (o, e) =>
{
datePicker.Date = e.Date;
((IElementController)datePicker).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);
}, year, month, day);
//ok
pickerDialog.SetButton((int)DialogButtonType.Positive, AppResources.AlertDismiss, OnDone);
//cancel
pickerDialog.SetButton((int)DialogButtonType.Negative, AppResources.PickerCancelText, OnCancel);
return pickerDialog;
}
IOS:建議我在IOS怎么做?
uj5u.com熱心網友回復:
如果我理解正確,你想顯示 DatePicker 的英文格式嗎?
如果是這樣,您可以修改Locale自定義渲染器中的日期選擇器。
iOS解決方案
[assembly: ExportRenderer(typeof(DatePicker), typeof(MyRenderer))]
namespace FormsApp.iOS
{
class MyRenderer : DatePickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
if(Control != null)
{
UIDatePicker picker = Control.InputView as UIDatePicker;
picker.Locale = new NSLocale("us");
}
}
}
}
前

后

If you want the Datepicker only display month and day for selecting item , it could be a little complex , because iOS does not provide the option/mode to achieve that , you need to create a view and controller that implement the UIPickerViewDelegate and create your own .
Refer to

###After

Refer to
DatePickerDialog in arabic language
Set Android DatePicker title language
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/325250.html
標籤:沙马林 xamarin.forms 安卓系统 xamarin.ios 自定义渲染器
