protected virtual void UpdateDrawerLockMode(FlyoutBehavior behavior) { AddFlyoutContentToLayoutIfNeeded(behavior); switch (behavior) { case FlyoutBehavior.Disabled: CloseDrawers(); Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, false); _currentLockMode = LockModeLockedClosed; SetDrawerLockMode(_currentLockMode); _content.SetPadding(0, _content.PaddingTop, _content.PaddingRight, _content.PaddingBottom); break; case FlyoutBehavior.Flyout: _currentLockMode = LockModeUnlocked; SetDrawerLockMode(_currentLockMode); _content.SetPadding(0, _content.PaddingTop, _content.PaddingRight, _content.PaddingBottom); break; case FlyoutBehavior.Locked: Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, true); _currentLockMode = LockModeLockedOpen; SetDrawerLockMode(_currentLockMode); _content.SetPadding((int)FlyoutWidth, _content.PaddingTop, _content.PaddingRight, _content.PaddingBottom); break; } UpdateScrim(_scrimBrush); }
protected virtual void UpdateDrawerLockMode(FlyoutBehavior behavior) { switch (behavior) { case FlyoutBehavior.Disabled: CloseDrawers(); Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, false); _currentLockMode = LockModeLockedClosed; SetDrawerLockMode(_currentLockMode); _content.SetPadding(0, _content.PaddingTop, _content.PaddingRight, _content.PaddingBottom); break; case FlyoutBehavior.Flyout: _currentLockMode = LockModeUnlocked; SetDrawerLockMode(_currentLockMode); _content.SetPadding(0, _content.PaddingTop, _content.PaddingRight, _content.PaddingBottom); break; case FlyoutBehavior.Locked: Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, true); _currentLockMode = LockModeLockedOpen; SetDrawerLockMode(_currentLockMode); _content.SetPadding(_flyoutWidth, _content.PaddingTop, _content.PaddingRight, _content.PaddingBottom); break; } unchecked { SetScrimColor(behavior == FlyoutBehavior.Locked ? Color.Transparent.ToAndroid() : (int)DefaultScrimColor); } }
public MovieCategoryViewHolder (View itemView, int viewType) : base (itemView) { //Creates and caches our views defined in our layout if (viewType == 0) // TODO: Calculate this. I don't think this is a good way to ensure consistent presentation across different device resolutions itemView.SetPadding (itemView.PaddingLeft, itemView.PaddingTop + 110, itemView.PaddingRight, itemView.PaddingBottom); this.CategoryName = itemView.FindViewById<TextView>(Resource.Id.movie_category_item_txtCategoryName); this.MovieList = itemView.FindViewById<RecyclerView>(Resource.Id.movie_category_item_lstMovies); }
protected override void OnDetached() { if (!IsDisposed) { // Check disposed _view.Background = _orgDrawable; if (Control == null) { _view.SetPadding(0, 0, 0, 0); _view.ClipToOutline = false; } } _border?.Dispose(); _border = null; _view = null; }
public override void Apply(View view, ViewGroup.LayoutParams layoutParams) { view.SetPadding( Left.HasValue ? Left.Value : All.HasValue ? All.Value : view.PaddingLeft, Top.HasValue ? Top.Value : All.HasValue ? All.Value : view.PaddingTop, Right.HasValue ? Right.Value : All.HasValue ? All.Value : view.PaddingRight, Bottom.HasValue ? Bottom.Value : All.HasValue ? All.Value : view.PaddingBottom ); }
private void UpdateTab(int tabIndex) { var page = Element.GetChildPageWithTransform(tabIndex); var menu = (BottomNavigationMenuView)_bottomNavigationView.GetChildAt(0); var isTitledisabled = TabbedPageTransforms.GetHideTitle(page); var view = menu.GetChildAt(tabIndex); if (view == null) { return; } if (view is BottomNavigationItemView itemView) { itemView.SetShifting(false); itemView.SetBackground(null); itemView.SetBackgroundColor(Android.Graphics.Color.Transparent); for (int j = 0; j < itemView.ChildCount; j++) { UIView childView = itemView.GetChildAt(j); if (childView is BaselineLayout baselineLayout) { if (isTitledisabled) { childView.Visibility = ViewStates.Gone; childView.SetPadding(0, 0, 0, 0); } for (int z = 0; z < baselineLayout.ChildCount; z++) { var textview = baselineLayout.GetChildAt(z); textview.SetPadding(0, 0, 0, 0); if (isTitledisabled) { textview.Visibility = ViewStates.Gone; } } } else if (isTitledisabled && childView is ImageView icon) { FrameLayout.LayoutParams parames = (FrameLayout.LayoutParams)icon.LayoutParameters; parames.Height = LayoutParams.MatchParent; parames.Width = LayoutParams.MatchParent; itemView.SetChecked(false); parames.SetMargins(0, 8, 0, 8); } } } }
public static void UpdateBackground(Border border, Android.Views.View view) { var strokeThickness = border.StrokeThickness; var context = view.Context; // create stroke drawable GradientDrawable strokeDrawable = null; // if thickness exists, set stroke drawable stroke and radius if (strokeThickness.HorizontalThickness + strokeThickness.VerticalThickness > 0) { strokeDrawable = new GradientDrawable(); strokeDrawable.SetColor(border.BackgroundColor.ToAndroid()); // choose thickest margin // the content is padded so it will look like the margin is with the given thickness strokeDrawable.SetStroke((int)context.ToPixels(strokeThickness.ThickestSide()), border.Stroke.ToAndroid()); strokeDrawable.SetCornerRadius((float)border.CornerRadius); } // create background drawable var backgroundDrawable = new GradientDrawable(); // set background drawable color based on Border's background color backgroundDrawable.SetColor(border.BackgroundColor.ToAndroid()); backgroundDrawable.SetCornerRadius((float)border.CornerRadius); if (strokeDrawable != null) { // if stroke drawable exists, create a layer drawable containing both stroke and background drawables var ld = new LayerDrawable(new Drawable[] { strokeDrawable, backgroundDrawable }); ld.SetLayerInset(1, (int)context.ToPixels(strokeThickness.Left), (int)context.ToPixels(strokeThickness.Top), (int)context.ToPixels(strokeThickness.Right), (int)context.ToPixels(strokeThickness.Bottom)); //view.SetBackgroundDrawable(ld); view.Background = ld; } else { //view.SetBackgroundDrawable(backgroundDrawable); view.Background = backgroundDrawable; } // set Android.View's padding to take into account the stroke thickiness view.SetPadding( (int)context.ToPixels(strokeThickness.Left + border.Padding.Left), (int)context.ToPixels(strokeThickness.Top + border.Padding.Top), (int)context.ToPixels(strokeThickness.Right + border.Padding.Right), (int)context.ToPixels(strokeThickness.Bottom + border.Padding.Bottom)); }
public void ShowToastMessage(string message, NotificationTypeEnum messageType) { Color backgroundHexColor = Color.ParseColor("#22c064"); if (messageType == NotificationTypeEnum.Info) { backgroundHexColor = Color.ParseColor("#1274d1"); } if (messageType == NotificationTypeEnum.Warning) { backgroundHexColor = Color.IndianRed; } if (messageType == NotificationTypeEnum.Danger) { backgroundHexColor = Color.Red; } var length = messageType == NotificationTypeEnum.Warning || messageType == NotificationTypeEnum.Danger ? ToastLength.Long : ToastLength.Short; // To dismiss existing toast, otherwise, the screen will be populated with it if the user do so _instance?.Cancel(); _instance = Toast.MakeText(Android.App.Application.Context, message, length); //_instance.SetGravity(GravityFlags.FillHorizontal | GravityFlags.Top, 0, 0); _instance.SetGravity(GravityFlags.Top, 0, 0); GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.SetCornerRadius(3f); //set corner radius //add icon and change background color/text TODO View tView = _instance.View; tView.SetMinimumHeight(40); tView.SetBackgroundDrawable(gradientDrawable); tView.Background.SetColorFilter(backgroundHexColor, PorterDuff.Mode.SrcIn);//Gets the actual oval background of the Toast then sets the color filter tView.SetPadding(10, 10, 10, 10); TextView text = (TextView)tView.FindViewById(Android.Resource.Id.Message); text.SetTextColor(Color.White); _instance.Show(); }
void SetTabItems() { BottomBarTab [] tabs = Element.Children.Select(page => { var tabIconId = ResourceManagerEx.IdFromTitle(page.Icon, ResourceManager.DrawableClass); return(new BottomBarTab(tabIconId, page.Title)); }).ToArray(); _bottomBar.SetItems(tabs); //remove padding if (_bottomBar.ItemContainer != null && _bottomBar.ItemContainer.ChildCount > 0) { for (int i = 0; i < _bottomBar.ItemContainer.ChildCount; i++) { Android.Views.View bottomBarTab = _bottomBar.ItemContainer.GetChildAt(i); bottomBarTab.SetPadding(0, 0, 0, 0); } } }
public static void UpdateBackground(Border border, Android.Views.View view) { var strokeThickness = border.StrokeThickness; var context = view.Context; var corners = new float[] { (float)border.CornerRadius.TopLeft, (float)border.CornerRadius.TopLeft, (float)border.CornerRadius.TopRight, (float)border.CornerRadius.TopRight, (float)border.CornerRadius.BottomRight, (float)border.CornerRadius.BottomRight, (float)border.CornerRadius.BottomLeft, (float)border.CornerRadius.BottomLeft }; GradientDrawable dab = null; dab = new GradientDrawable(); if (strokeThickness.HorizontalThickness + strokeThickness.VerticalThickness > 0) { dab.SetColor(border.BackgroundColor.ToAndroid()); dab.SetStroke((int)context.ToPixels(strokeThickness.Max()), border.Stroke.ToAndroid()); } dab.SetCornerRadii(corners); dab.SetColor(border.BackgroundColor.ToAndroid()); dab.SetCornerRadii(corners); view.Background = dab; view.SetPadding( (int)context.ToPixels(strokeThickness.Left + border.Padding.Left), (int)context.ToPixels(strokeThickness.Top + border.Padding.Top), (int)context.ToPixels(strokeThickness.Right + border.Padding.Right), (int)context.ToPixels(strokeThickness.Bottom + border.Padding.Bottom)); }
public void AddItem(string itemID, View item) { if (this.items.Count == 0) { item.LayoutParameters = new ViewGroup.LayoutParams(92, 92); item.SetPadding(10, 10, 10, 10); this.items[itemID] = item; LinearLayout firstRow = new LinearLayout(this.Context); firstRow.Orientation = Orientation.Horizontal; firstRow.SetHorizontalGravity(GravityFlags.Center); firstRow.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent); firstRow.AddView(item); this.rows[0] = firstRow; this.baseLayout.AddView(firstRow); } else { if (this.items.ContainsKey(itemID)) { throw new InvalidOperationException("An item with the same key already exists in the scroll view!"); }//end if // Get the last row (LinearLayout) int lastRowIndex = this.rows.Keys.Max(); LinearLayout lastRow = this.rows[lastRowIndex]; item.LayoutParameters = new ViewGroup.LayoutParams(92, 92); item.SetPadding(10, 10, 10, 10); this.items[itemID] = item; if (lastRow.ChildCount < 3) { // Last row still has room lastRow.AddView(item); } else { LinearLayout newRow = new LinearLayout(this.Context); newRow.Orientation = Orientation.Horizontal; newRow.SetHorizontalGravity(GravityFlags.Center); newRow.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent); newRow.AddView(item); this.rows[++lastRowIndex] = newRow; this.baseLayout.AddView(newRow); }//end if else }//end if else }
public static void SetPadding(this av.View view, Padding padding) { view.SetPadding(padding.Left, padding.Top, padding.Right, padding.Bottom); }
private View CreateCustomToolbarItem(string name, Context context, IAttributeSet attrs) { // android.support.v7.widget.Toolbar // android.support.v7.view.menu.ActionMenuItemView View view = null; try { if (ActionMenuItemViewClass == null) { ActionMenuItemViewClass = ClassLoader.LoadClass(name); } } catch (ClassNotFoundException ex) { return(null); } if (ActionMenuItemViewClass == null) { return(null); } if (ActionMenuItemViewConstructor == null) { try { ActionMenuItemViewConstructor = ActionMenuItemViewClass.GetConstructor(new Class[] { Class.FromType(typeof(Context)), Class.FromType(typeof(IAttributeSet)) }); } catch (SecurityException) { return(null); } catch (NoSuchMethodException) { return(null); } } if (ActionMenuItemViewConstructor == null) { return(null); } try { Java.Lang.Object[] args = new Java.Lang.Object[] { context, (Java.Lang.Object)attrs }; view = (View)(ActionMenuItemViewConstructor.NewInstance(args)); } catch (IllegalArgumentException) { return(null); } catch (InstantiationException) { return(null); } catch (IllegalAccessException) { return(null); } catch (InvocationTargetException) { return(null); } if (null == view) { return(null); } View v = view; v.SetPadding(0, 0, 0, 0); new Handler().Post(() => { try { if (v is LinearLayout) { var ll = (LinearLayout)v; for (int i = 0; i < ll.ChildCount; i++) { var button = ll.GetChildAt(i) as Android.Widget.Button; System.Diagnostics.Debug.WriteLine("------button------->" + button.Text); if (button != null) { button.SetPadding(0, 0, 0, 0); var title = button.Text; if (!string.IsNullOrEmpty(title) && title.Length == 1) { button.SetTypeface(Typeface, TypefaceStyle.Normal); } } } } else if (v is TextView) { var tv = (TextView)v; tv.SetPadding(0, 0, 0, 0); string title = tv.Text; //System.Diagnostics.Debug.WriteLine("-----title-------->" + title); if (!string.IsNullOrEmpty(title) && title.Length == 1) { tv.SetTextSize(ComplexUnitType.Sp, 20); tv.SetTypeface(Typeface, TypefaceStyle.Normal); } } } catch (ClassCastException) { } }); return(view); }
private static void UpdateTopBottomPadding(View view, int topPadding, int bottomPadding) { if (ViewCompat.IsPaddingRelative(view)) { ViewCompat.SetPaddingRelative(view, ViewCompat.GetPaddingStart(view), topPadding, ViewCompat.GetPaddingEnd(view), bottomPadding); } else { view.SetPadding(view.PaddingLeft, topPadding, view.PaddingRight, bottomPadding); } }