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.Aqua); //uri for a free video var uri = Android.Net.Uri.Parse ("https://www.dropbox.com/s/hi45psyy0wq9560/PigsInAPolka1943.mp4?dl=1"); //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<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.Aqua); //uri for a free video var uri = Android.Net.Uri.Parse("http://www.androidbegin.com/tutorial/AndroidCommercial.3gp"); //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 <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); }
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); }
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 <Android.Widget.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.Aqua); if (playFromAssets) { //relative path to video in Assets folder var filePath = "SampleVideo.mp4"; ISurfaceHolder holder = videoView.Holder; holder.AddCallback(this); player = new Android.Media.MediaPlayer(); AssetFileDescriptor afd = Context.Assets.OpenFd(filePath); player.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length); } else { //uri for a free video //var uri = Android.Net.Uri.Parse ("https://www.dropbox.com/s/hi45psyy0wq9560/PigsInAPolka1943.mp4?dl=1"); var uri = Android.Net.Uri.Parse("android.resource://" + Forms.Context.PackageName + "/" + Resource.Raw.SampleVideo); //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; }
private void populateUnifiedNativeAdView(UnifiedNativeAd nativeAd, UnifiedNativeAdView adView) { // Find View Ctrl primaryView = adView.FindViewById <TextView>(Resource.Id.ad_primary); secondaryView = adView.FindViewById <TextView>(Resource.Id.ad_secondary); //tertiaryView = adView.FindViewById<TextView>(Resource.Id.ad_body); ratingBar = adView.FindViewById <RatingBar>(Resource.Id.ad_rating); ratingBar.Enabled = false; callToActionView = adView.FindViewById <Android.Widget.Button>(Resource.Id.ad_call_to_action); iconView = adView.FindViewById <ImageView>(Resource.Id.ad_icon); // Ad data string store = nativeAd.Store; string advertiser = nativeAd.Advertiser; string headline = nativeAd.Headline; string cta = nativeAd.CallToAction; float starRating = nativeAd.StarRating?.FloatValue() ?? 0.0f; Drawable icon = nativeAd.Icon?.Drawable ?? null; Drawable image = nativeAd.Images.Count > 0 ? nativeAd.Images[0].Drawable : null; // dynamic string secondaryText; // Set value in view adView.CallToActionView = callToActionView; adView.HeadlineView = primaryView; secondaryView.Visibility = ViewStates.Visible; if (AdHasOnlyStore(nativeAd)) { adView.StoreView = secondaryView; secondaryText = store; } else if (!string.IsNullOrEmpty(advertiser)) { adView.AdvertiserView = secondaryView; secondaryText = advertiser; } else { secondaryText = ""; } primaryView.Text = headline; // CallToActionView callToActionView.Text = cta; callToActionView.SetBackgroundColor(ButtonColor); // Set the secondary view to be the star rating if available. if (starRating > 0) { secondaryView.Visibility = ViewStates.Gone; ratingBar.Visibility = ViewStates.Visible; ratingBar.Max = 5; ratingBar.Rating = starRating; ratingBar.StepSize = 0.1f; adView.StarRatingView = ratingBar; } else { secondaryView.Text = secondaryText; secondaryView.Visibility = ViewStates.Visible; ratingBar.Visibility = ViewStates.Gone; } if (image != null) { iconView.Visibility = ViewStates.Visible; iconView.SetImageDrawable(image); } else if (icon != null) { iconView.Visibility = ViewStates.Visible; iconView.SetImageDrawable(icon); } else { iconView.Visibility = ViewStates.Gone; } adView.SetNativeAd(nativeAd); }