private void Control_Click(object sender, EventArgs e) { Picker model = Element; CustomNumberPicker picker = new CustomNumberPicker(Context); picker.TextColor = (Element as BetterPicker).PopupTextColor.ToAndroid(); picker.ValueChanged += SelectionChanged; if (model.Items != null && model.Items.Any()) { picker.MaxValue = model.Items.Count - 1; picker.MinValue = 0; picker.SetBackgroundColor((Element as BetterPicker).PopupBackground.ToAndroid()); picker.SetDisplayedValues(model.Items.ToArray()); picker.TextColor = (Element as BetterPicker).PopupTextColor.ToAndroid(); SetPickerDividerColor(picker, (Element as BetterPicker).PopupTextColor.ToAndroid()); picker.WrapSelectorWheel = false; picker.Value = model.SelectedIndex; } LinearLayout layout = new LinearLayout(Context) { Orientation = Orientation.Vertical }; layout.SetBackgroundColor((Element as BetterPicker).PopupBackground.ToAndroid()); layout.AddView(picker); ElementController.SetValueFromRenderer(VisualElement.IsFocusedProperty, true); AlertDialog.Builder builder = new AlertDialog.Builder(Context); builder.SetView(layout); builder.SetTitle(model.Title ?? ""); _dialog = builder.Create(); Android.Widget.Button Button = _dialog.GetButton((int)DialogButtonType.Positive); if (Button != null) { Button.SetTextColor((Element as BetterPicker).PopupTextColor.ToAndroid()); } Button = _dialog.GetButton((int)DialogButtonType.Negative); if (Button != null) { Button.SetTextColor((Element as BetterPicker).PopupTextColor.ToAndroid()); } Button = _dialog.GetButton((int)DialogButtonType.Neutral); if (Button != null) { Button.SetTextColor((Element as BetterPicker).PopupTextColor.ToAndroid()); } _dialog.Window.SetBackgroundDrawable(new ColorDrawable((Element as BetterPicker).PopupBackground.ToAndroid())); _dialog.DismissEvent += (ssender, args) => { ElementController?.SetValueFromRenderer(VisualElement.IsFocusedProperty, false); }; _dialog.Show(); }
protected override void OnElementChanged(ElementChangedEventArgs <TabSlidingView> e) { base.OnElementChanged(e); _tabSlidingView = e.NewElement; // コンテクストは継承されたものをそのまま使った var horizontalScrollView = new HorizontalScrollView(_context); var linerLayout = new LinearLayout(_context); for (int i = 0; i < 20; i++) { // ボタンのレイアウトを整えるiOSでもこのような機能があるといいな var layoutParams = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.MatchParent , LinearLayout.LayoutParams.WrapContent); // コンテクストの為に親が決まる訳ではない(この前の親をとり除けというエラーは一体何だったのだろうか) var btn = new Android.Widget.Button(_context); btn.Id = i; btn.Text = i.ToString(); btn.SetBackgroundColor(Android.Graphics.Color.White); btn.SetTextColor(Android.Graphics.Color.LightGray); linerLayout.AddView(btn, layoutParams); } horizontalScrollView.AddView(linerLayout); base.SetNativeControl(horizontalScrollView); }
//https://github.com/xamarin/customer-success-samples/blob/master/samples/Xamarin.Forms/FormsNativeVideoPlayer/Droid/VideoPlayer_CustomRenderer.cs protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e) { base.OnElementChanged(e); //Get LayoutInflater and inflate from axml //Important note, this project utilizes a layout-land folder in the Resources folder //Android will use this folder with layout files for Landscape Orientations //This is why we don't have to worry about the layout of the play button, it doesn't exist in landscape layout file!!! var activity = Context as Activity; var viewHolder = activity.LayoutInflater.Inflate(Resource.Layout.Main, this, false); view = viewHolder; AddView(view); //Get and set Views videoView = FindViewById <VideoView>(Resource.Id.SampleVideoView); playButton = FindViewById <Android.Widget.Button>(Resource.Id.PlayVideoButton); //Give some color to the play button, but not important playButton.SetBackgroundColor(Android.Graphics.Color.White); playButton.SetTextColor(Android.Graphics.Color.Black); //uri for a free video var uri = Android.Net.Uri.Parse("http://vjs.zencdn.net/v/oceans.mp4"); //Set the videoView with our uri, this could also be a local video on device videoView.SetVideoURI(uri); //Assign click event on our play button to play the video playButton.Click += PlayVideo; }
protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); MessagingCenter.Subscribe <RootPage, AlertArguments> (this, "DisplayAlert", (sender, arguments) => { //If you would like to use style attributes, you can pass this into the builder // ContextThemeWrapper customDialog = new ContextThemeWrapper(Context, Resource.Style.AlertDialogCustom); // AlertDialog.Builder builder = new AlertDialog.Builder(customDialog); //Create instance of AlertDialog.Builder and create the alert AlertDialog.Builder builder = new AlertDialog.Builder(Context); var alert = builder.Create(); //Utilize context to get LayoutInflator to set the view used for the dialog var layoutInflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService); alert.SetView(layoutInflater.Inflate(Resource.Layout.CustomDialog, null)); //Create a custom title element TextView title = new TextView(Context) { Text = arguments.Title, }; title.SetTextColor(Android.Graphics.Color.DodgerBlue); title.SetBackgroundColor(Android.Graphics.Color.White); //Add the custom title to the AlertDialog alert.SetCustomTitle(title); //Set the buttons text and click handler events if (arguments.Accept != null) { alert.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(true)); } alert.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(false)); alert.CancelEvent += (o, args) => { arguments.SetResult(false); }; alert.Show(); //This code grabs the line that separates the title and dialog. int titleDividerId = Resources.GetIdentifier("titleDivider", "id", "android"); Android.Views.View titleDivider = alert.FindViewById(titleDividerId); if (titleDivider != null) { titleDivider.SetBackgroundColor(Android.Graphics.Color.DarkRed); } //Set properties of the buttons Android.Widget.Button positiveButton = alert.GetButton((int)DialogButtonType.Positive); positiveButton.SetTextColor(Android.Graphics.Color.Green); positiveButton.SetBackgroundColor(Android.Graphics.Color.White); Android.Widget.Button negativeButton = alert.GetButton((int)DialogButtonType.Negative); negativeButton.SetTextColor(Android.Graphics.Color.Red); negativeButton.SetBackgroundColor(Android.Graphics.Color.White); //Set the text of the TextView in the dialog var textView = alert.FindViewById <TextView>(Resource.Id.textview); textView.SetText(arguments.Message, null); }); }
private Android.Widget.Button GetButton(ToolbarItem item) { var button = new Android.Widget.Button(_rightMenuLayout.Context) { Text = item.Text }; button.Click += (object sender, System.EventArgs e) => { item.Activate(); }; //button.SetTextColor(Element.BarTextColor.ToAndroid()); button.SetTextColor(Android.Graphics.Color.Red); button.SetBackgroundColor(Android.Graphics.Color.Transparent); button.SetMinWidth(10); button.SetMinimumWidth(10); button.SetPadding(5, 0, 5, 0); button.LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); return(button); }
/// <summary> /// 标注点击时 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnMarkerClick(object sender, BaiduMap.MarkerClickEventArgs e) { try { if (!string.IsNullOrEmpty(e.P0.Title)) { var pin = Map.Pins.Find(e.P0); if (pin?.Terminal != null) { var color = pin?.Terminal?.RankColor ?? "#4a89dc"; //cardView var cardView = new CardView(Context) { Radius = 15 }; cardView.SetCardBackgroundColor(Color.FromHex(color).ToAndroid()); //布局 var layout = new LinearLayout(Context) { Orientation = Orientation.Vertical }; layout.SetPadding(10, 10, 10, 10); //Title var tview = new TextView(Context); tview.SetPadding(10, 10, 10, 10); tview.SetTextColor(Color.White.ToAndroid()); tview.TextSize = 12; tview.Text = e.P0.Title; //Button var param = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent) { Height = 45 }; var button = new Android.Widget.Button(Context); button.Text = "去拜访"; button.TextSize = 10; button.LayoutParameters = param; button.SetBackgroundResource(Resource.Drawable.roundShape); button.SetTextColor(Color.White.ToAndroid()); button.Click += (sender, ar) => { var pin = Map.Pins.Find(e.P0); pin?.SendClicked(pin?.Terminal); }; layout.AddView(tview); layout.AddView(button); cardView.AddView(layout); var window = new InfoWindow(cardView, e.P0.Position, -e.P0.Icon.Bitmap.Height); NativeMap.Map.ShowInfoWindow(window); } } } catch (Exception) { } }
private void Control_Click(object sender, EventArgs e) { Picker model = Element; var picker = new NumberPicker(Context); if (model.Items != null && model.Items.Any()) { picker.MaxValue = model.Items.Count - 1; picker.MinValue = 0; picker.SetDisplayedValues(model.Items.ToArray()); picker.WrapSelectorWheel = false; picker.DescendantFocusability = DescendantFocusability.BlockDescendants; picker.Value = model.SelectedIndex; } var layout = new LinearLayout(Context) { Orientation = Orientation.Vertical }; layout.AddView(picker); ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, true); var builder = new AlertDialog.Builder(Context); builder.SetView(layout); builder.SetTitle(model.Title ?? ""); builder.SetNegativeButton(global::Android.Resource.String.Cancel, (s, a) => { ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); // It is possible for the Content of the Page to be changed when Focus is changed. // In this case, we'll lose our Control. Control?.ClearFocus(); _dialog = null; }); builder.SetPositiveButton(global::Android.Resource.String.Ok, (s, a) => { ElementController.SetValueFromRenderer(Picker.SelectedIndexProperty, picker.Value); // It is possible for the Content of the Page to be changed on SelectedIndexChanged. // In this case, the Element & Control will no longer exist. if (Element != null) { if (model.Items.Count > 0 && Element.SelectedIndex >= 0) { Control.Text = model.Items[Element.SelectedIndex]; } ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); // It is also possible for the Content of the Page to be changed when Focus is changed. // In this case, we'll lose our Control. Control?.ClearFocus(); } _dialog = null; }); _dialog = builder.Create(); _dialog.DismissEvent += (ssender, args) => { ElementController?.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); }; _dialog.Show(); _dialog.Window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.White)); //modify the color of the button in the dialog box Android.Widget.Button nbutton = _dialog.GetButton((int)Android.Content.DialogButtonType.Positive); nbutton.SetTextColor(Android.Graphics.Color.ParseColor("#3367b0")); nbutton = _dialog.GetButton((int)Android.Content.DialogButtonType.Negative); nbutton.SetTextColor(Android.Graphics.Color.ParseColor("#3367b0")); nbutton.TextSize = 16f; }
private void Control_Click(object sender, EventArgs e) { Picker model = Element; var picker = new NumberPicker(Context); if (model.Items != null && model.Items.Any()) { // set style here picker.MaxValue = model.Items.Count - 1; picker.MinValue = 0; picker.SetDisplayedValues(model.Items.ToArray()); picker.WrapSelectorWheel = false; picker.Value = model.SelectedIndex; } var layout = new LinearLayout(Context) { Orientation = Android.Widget.Orientation.Vertical }; layout.AddView(picker); //layout.SetBackground(ContextCompat.GetDrawable(Android.App.Application.Context, Resource.Drawable.dialogBackground)); ElementController.SetValueFromRenderer(VisualElement.IsFocusedProperty, true); var builder = new AlertDialog.Builder(Context); builder.SetView(layout); builder.SetTitle(model.Title ?? ""); builder.SetNegativeButton("Cancel ", (s, a) => { ElementController.SetValueFromRenderer(VisualElement.IsFocusedProperty, false); // It is possible for the Content of the Page to be changed when Focus is changed. // In this case, we'll lose our Control. Control?.ClearFocus(); _dialog = null; }); builder.SetPositiveButton("Ok ", (s, a) => { ElementController.SetValueFromRenderer(Picker.SelectedIndexProperty, picker.Value); // It is possible for the Content of the Page to be changed on SelectedIndexChanged. // In this case, the Element & Control will no longer exist. if (Element != null) { if (model.Items.Count > 0 && Element.SelectedIndex >= 0) { Control.Text = model.Items[Element.SelectedIndex]; } ElementController.SetValueFromRenderer(VisualElement.IsFocusedProperty, false); // It is also possible for the Content of the Page to be changed when Focus is changed. // In this case, we'll lose our Control. Control?.ClearFocus(); } _dialog = null; }); _dialog = builder.Create(); _dialog.DismissEvent += (ssender, args) => { ElementController?.SetValueFromRenderer(VisualElement.IsFocusedProperty, false); }; _dialog.ShowEvent += (ssender, args) => { var dialog = (AlertDialog)ssender; Android.Widget.Button negativeButton = dialog.GetButton(DialogButtonType.Negative.GetHashCode()); negativeButton.SetTextColor(Android.Graphics.Color.Gray); }; _dialog.Show(); }