Button Constructors

Definition

Overloads

Button(Context)

Simple constructor to use when creating a button from code.

Button(Context, IAttributeSet)

LayoutInflater calls this constructor when inflating a Button from XML.

Button(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Button(Context, IAttributeSet, Int32)

This constructor allows a Button subclass to use its own class-specific base style from a theme attribute when inflating.

Button(Context, IAttributeSet, Int32, Int32)

This constructor allows a Button subclass to use its own class-specific base style from either a theme attribute or style resource when inflating.

Button(Context)

Simple constructor to use when creating a button from code.

[Android.Runtime.Register(".ctor", "(Landroid/content/Context;)V", "")]
public Button (Android.Content.Context? context);
[<Android.Runtime.Register(".ctor", "(Landroid/content/Context;)V", "")>]
new Android.Widget.Button : Android.Content.Context -> Android.Widget.Button

Parameters

context
Context

The Context the Button is running in, through which it can access the current theme, resources, etc.

Attributes

Remarks

Simple constructor to use when creating a button from code.

Java documentation for android.widget.Button.Button(android.content.Context).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Button(Context, IAttributeSet)

LayoutInflater calls this constructor when inflating a Button from XML.

[Android.Runtime.Register(".ctor", "(Landroid/content/Context;Landroid/util/AttributeSet;)V", "")]
public Button (Android.Content.Context? context, Android.Util.IAttributeSet? attrs);
[<Android.Runtime.Register(".ctor", "(Landroid/content/Context;Landroid/util/AttributeSet;)V", "")>]
new Android.Widget.Button : Android.Content.Context * Android.Util.IAttributeSet -> Android.Widget.Button

Parameters

context
Context

The Context the view is running in, through which it can access the current theme, resources, etc.

attrs
IAttributeSet

The attributes of the XML Button tag being used to inflate the view.

Attributes

Remarks

LayoutInflater calls this constructor when inflating a Button from XML. The attributes defined by the current theme's android.R.attr#buttonStyle android:buttonStyle override base view attributes.

You typically do not call this constructor to create your own button instance in code. However, you must override this constructor when creating custom views.

Java documentation for android.widget.Button.Button(android.content.Context, android.util.AttributeSet).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Button(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

protected Button (IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer);
new Android.Widget.Button : nativeint * Android.Runtime.JniHandleOwnership -> Android.Widget.Button

Parameters

javaReference
IntPtr

nativeint

A IntPtrcontaining a Java Native Interface (JNI) object reference.

transfer
JniHandleOwnership

A JniHandleOwnershipindicating how to handle javaReference

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Button(Context, IAttributeSet, Int32)

This constructor allows a Button subclass to use its own class-specific base style from a theme attribute when inflating.

[Android.Runtime.Register(".ctor", "(Landroid/content/Context;Landroid/util/AttributeSet;I)V", "")]
public Button (Android.Content.Context? context, Android.Util.IAttributeSet? attrs, int defStyleAttr);
[<Android.Runtime.Register(".ctor", "(Landroid/content/Context;Landroid/util/AttributeSet;I)V", "")>]
new Android.Widget.Button : Android.Content.Context * Android.Util.IAttributeSet * int -> Android.Widget.Button

Parameters

context
Context

The Context the Button is running in, through which it can access the current theme, resources, etc.

attrs
IAttributeSet

The attributes of the XML Button tag that is inflating the view.

defStyleAttr
Int32

The resource identifier of an attribute in the current theme whose value is the the resource id of a style. The specified style’s attribute values serve as default values for the button. Set this parameter to 0 to avoid use of default values.

Attributes

Remarks

This constructor allows a Button subclass to use its own class-specific base style from a theme attribute when inflating. The attributes defined by the current theme's defStyleAttr override base view attributes.

For Button's base view attributes see android.R.styleable#Button Button Attributes, android.R.styleable#TextView TextView Attributes, android.R.styleable#View View Attributes.

Java documentation for android.widget.Button.Button(android.content.Context, android.util.AttributeSet, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Button(Context, IAttributeSet, Int32, Int32)

This constructor allows a Button subclass to use its own class-specific base style from either a theme attribute or style resource when inflating.

[Android.Runtime.Register(".ctor", "(Landroid/content/Context;Landroid/util/AttributeSet;II)V", "")]
public Button (Android.Content.Context? context, Android.Util.IAttributeSet? attrs, int defStyleAttr, int defStyleRes);
[<Android.Runtime.Register(".ctor", "(Landroid/content/Context;Landroid/util/AttributeSet;II)V", "")>]
new Android.Widget.Button : Android.Content.Context * Android.Util.IAttributeSet * int * int -> Android.Widget.Button

Parameters

context
Context

The Context the Button is running in, through which it can access the current theme, resources, etc.

attrs
IAttributeSet

The attributes of the XML Button tag that is inflating the view.

defStyleAttr
Int32

The resource identifier of an attribute in the current theme whose value is the the resource id of a style. The specified style’s attribute values serve as default values for the button. Set this parameter to 0 to avoid use of default values.

defStyleRes
Int32

The identifier of a style resource that supplies default values for the button, used only if defStyleAttr is 0 or cannot be found in the theme. Set this parameter to 0 to avoid use of default values.

Attributes

Remarks

This constructor allows a Button subclass to use its own class-specific base style from either a theme attribute or style resource when inflating. To see how the final value of a particular attribute is resolved based on your inputs to this constructor, see android.view.View#View(Context, AttributeSet, int, int).

Java documentation for android.widget.Button.Button(android.content.Context, android.util.AttributeSet, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to