public static float ThemedResourceAttribute(this Context aContext, int aResourceId) { TypedValue value = new TypedValue(); aContext.Theme.ResolveAttribute(aResourceId, value, true); IWindowManager windowManager = aContext.GetSystemService(Context.WindowService).JavaCast <IWindowManager>(); DisplayMetrics outMetrics = new DisplayMetrics(); windowManager.DefaultDisplay.GetMetrics(outMetrics); return(value.GetDimension(outMetrics)); }
internal BookmarkItemView(Context context) : base(context) { Orientation = Orientation.Horizontal; LayoutParameters = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); SetGravity(GravityFlags.CenterVertical | GravityFlags.FillHorizontal); Clickable = true; BookmarkLabel = new TextView(context) { LayoutParameters = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent), }; // Height var listItemHeightValue = new TypedValue(); context.Theme.ResolveAttribute(Android.Resource.Attribute.ListPreferredItemHeight, listItemHeightValue, true); SetMinimumHeight((int)listItemHeightValue.GetDimension(Resources.DisplayMetrics)); // Left and right margin var listItemLeftMarginValue = new TypedValue(); context.Theme.ResolveAttribute(Android.Resource.Attribute.ListPreferredItemPaddingStart, listItemLeftMarginValue, true); var listItemRightMarginValue = new TypedValue(); context.Theme.ResolveAttribute(Android.Resource.Attribute.ListPreferredItemPaddingEnd, listItemRightMarginValue, true); SetPadding((int)listItemLeftMarginValue.GetDimension(Resources.DisplayMetrics), 0, (int)listItemRightMarginValue.GetDimension(Resources.DisplayMetrics), 0); BookmarkLabel.Gravity = GravityFlags.CenterVertical | GravityFlags.FillHorizontal; // Selection animation on hover var selectableBackground = new TypedValue(); context.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackground, selectableBackground, true); SetBackgroundResource(selectableBackground.ResourceId); AddView(BookmarkLabel); }