Buttons – Android Push Examples

Posted on 38 views

This instance is to demo you lot to create a uncomplicated button, a push alongside left as well as correct image, a push alongside background image, a push alongside edge color, a push alongside edge radius, a circular push as well as clickable button. When user impact to the button, it responses as well as shows around toast message.

Button is available inwards android.widget.Button package. Let’s create these Buttons footstep past times step.

 This instance is to demo you lot to create a uncomplicated push Buttons - Android Button ExamplesRelated:
Android Button onClick
Simple Android Alert Dialog
Android Toast – How to Display Simple Toast Message inwards Android

Create a Project

Let’s start making these buttons past times creating novel android projection alongside next information.

Application name: Android Buttons Example
Company Domain: viralandroid.com
Package name: com.viralandroid.androidbuttonsexample
Minimum SDK: Android 2.2 (API 8 Froyo)

1. Simple Android Button

First of all, let’s create uncomplicated button. This contains lilliputian text, background color, etc. Add next code to your XML action layout file (main_activity.xml).

<button android:background="#25aaff" android:layout_height="wrap_content" android:layout_width="wrap_content" android:onclick="simpleButton" android:padding="10dp" android:text="This is Simple Android Button"></button>

To stimulate got push click, you lot accept to add together onClick attribute inwards your push as well as rank a push refer similar simpleButton.

To teach answer on push click you lot accept to add together next code to your coffee action file (MainActivity.xml).

public void simpleButton(View view) {         Toast.makeText(getApplicationContext(), "This is Simple Android Button", Toast.LENGTH_LONG).show();     }

2. Button With Icon In Left

Like above, add together next code to your XML as well as coffee file.
XML Code:

<button android:background="#25aaff" android:drawableleft="@android:drawable/sym_call_outgoing" android:layout_height="wrap_content" android:layout_margintop="10dp" android:layout_width="wrap_content" android:onclick="leftIconButton" android:padding="10dp" android:text="Button With Icon inwards Left"></button>

Java Code:

public void leftIconButton(View view) {         Toast.makeText(getApplicationContext(), "Android Button With Icon inwards Left", Toast.LENGTH_LONG).show();     }

3. Button With Icon In Right

XML Code:

<button android:background="#25aaff" android:drawableright="@android:drawable/sym_call_outgoing" android:layout_height="wrap_content" android:layout_margintop="10dp" android:layout_width="wrap_content" android:onclick="rightIconButton" android:padding="10dp" android:text="Button With Icon inwards Right"></button>

Java Code:

public void rightIconButton(View view) {         Toast.makeText(getApplicationContext(), "Android Button With Icon inwards Right", Toast.LENGTH_LONG).show();     }

4. Button With Background Image

XML Code:

<button android:background="@drawable/button_bg" android:layout_height="80dp" android:layout_margintop="10dp" android:layout_width="300dp" android:onclick="backgroundImageButton" android:padding="10dp" android:text="Button With Background Image"></button>

Java Code:

public void backgroundImageButton(View view) {         Toast.makeText(getApplicationContext(), "Android Button With Background Image", Toast.LENGTH_LONG).show();     }

5. Button With Border Color

At first, you lot accept to create a XML file inwards drawable folder called button_border.xml.
res/drawable/ button_border.xml

READ  [What is Printer in Hindi] प्रिटंर क्‍या है ?

XML Code:

<button android:background="@drawable/button_border" android:layout_height="70dp" android:layout_margintop="10dp" android:layout_width="250dp" android:onclick="borderButton" android:padding="10dp" android:text="Button With Border Color"></button>

Java Code:

public void borderButton(View view) {         Toast.makeText(getApplicationContext(), "Android Button With Border Color", Toast.LENGTH_LONG).show();     }

6. Button With Border Radius

Create border_radius.xml file inwards your drawable folder.
res/drawable/ border_radius.xml

XML Code:

<button android:background="@drawable/border_radius" android:layout_height="wrap_content" android:layout_margintop="10dp" android:layout_width="wrap_content" android:onclick="borderRadiusButton" android:padding="10dp" android:text="Button With Border Radius"></button>

Java Code:

public void borderRadiusButton(View view) {         Toast.makeText(getApplicationContext(), "Android Button With Border Radius", Toast.LENGTH_LONG).show();     }

7. Round Button

Create round_button.xml file inwards your drawable folder.
res/drawable/ round_button.xml

XML Code:

<button android:background="@drawable/round_button" android:layout_height="150dp" android:layout_margintop="10dp" android:layout_width="150dp" android:onclick="roundButton" android:padding="10dp" android:text="Round Button"></button>

Java Code:

public void roundButton(View view) {         Toast.makeText(getApplicationContext(), "Android Round Button", Toast.LENGTH_LONG).show();     }

That’s all. You accept done alongside each styles, next is the in conclusion XML as well as coffee file code of all buttons.
res/layout/ activity_main.xml

src/MainActivity.java