You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to have the possibility to create a MauiMaterialButton with a custom android style.
The current implementation extends MaterialButton and is exposing a constructor that accepts the android context only.
public MauiMaterialButton(Context context) : base(context) { }
Materialbutton also has a constructor accepting a style override (defStyleAttr).
public unsafe MaterialButton(Context context, IAttributeSet? attrs, int defStyleAttr) : base(IntPtr.Zero, JniHandleOwnership.DoNotTransfer) {...}
Without exposing this constructor it seems like there's no simple way to extend MauiMaterialButton to benefit from automatic image icon scaling and still define a custom (or variable) android style.
Public API Changes
public MauiMaterialButton(Context context, IAttributeSet? attrs, int defStyleAttr) : base(Context context, IAttributeSet? attrs, int defStyleAttr) { }
Intended Use-Case
I have a situation where I select an android style in a derived button handler based on a buttonType enum property.
private static int GetStyle(BindableObject element)
{
int style = Resource.Attribute.materialButtonStyle;
if (element is CustomButton btn)
{
var btnType = btn.ButtonType;
switch (btnType)
{
case CustomButtonType.Contained:
break;
case CustomButtonType.Outlined:
style = Resource.Attribute.materialOutlinedButtonStyle;
break;
...
case CustomButtonType.Text:
style = Resource.Attribute.materialTextButtonStyle;
break;
}
}
return style;
}
For this I need to override CreatePlatformView and create a new Materialbutton with the android style that corresponds to the buttonType enum. I can't use the MauiMaterialButton for this yet, as it does not expose the necessary constructor.
var button = new MaterialButton(Context, null, GetStyle((BindableObject)VirtualView))
The android styles are based on the Widget.MaterialComponents.Button styles, e.g. TextButton and OutlinedButton.
The text was updated successfully, but these errors were encountered:
Description
I would like to have the possibility to create a MauiMaterialButton with a custom android style.
The current implementation extends MaterialButton and is exposing a constructor that accepts the android context only.
public MauiMaterialButton(Context context) : base(context) { }
Materialbutton also has a constructor accepting a style override (defStyleAttr).
public unsafe MaterialButton(Context context, IAttributeSet? attrs, int defStyleAttr) : base(IntPtr.Zero, JniHandleOwnership.DoNotTransfer) {...}
Without exposing this constructor it seems like there's no simple way to extend MauiMaterialButton to benefit from automatic image icon scaling and still define a custom (or variable) android style.
Public API Changes
public MauiMaterialButton(Context context, IAttributeSet? attrs, int defStyleAttr) : base(Context context, IAttributeSet? attrs, int defStyleAttr) { }
Intended Use-Case
I have a situation where I select an android style in a derived button handler based on a buttonType enum property.
For this I need to override CreatePlatformView and create a new Materialbutton with the android style that corresponds to the buttonType enum. I can't use the MauiMaterialButton for this yet, as it does not expose the necessary constructor.
var button = new MaterialButton(Context, null, GetStyle((BindableObject)VirtualView))
The android styles are based on the Widget.MaterialComponents.Button styles, e.g. TextButton and OutlinedButton.
The text was updated successfully, but these errors were encountered: