Extend MauiMaterialButton to expose a constructor which accepts a style id override #22455
Labels
area-controls-button
Button, ImageButton
fixed-in-9.0.0-preview.7.24407.4
good first issue
Good for newcomers
proposal/accepted
Milestone
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: