0% found this document useful (0 votes)
28 views2 pages

AbhiAndroid Button Example Code

The document describes an Android application layout with two buttons. It includes the XML layout code with the button widgets and styles. It also includes the Java code for the MainActivity class that initializes the buttons, sets onclick listeners to display toast messages with the button text when clicked. The application demonstrates basic button usage and interactions in Android.

Uploaded by

Anonymous zrBShg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

AbhiAndroid Button Example Code

The document describes an Android application layout with two buttons. It includes the XML layout code with the button widgets and styles. It also includes the Java code for the MainActivity class that initializes the buttons, sets onclick listeners to display toast messages with the button text when clicked. The application demonstrates basic button usage and interactions in Android.

Uploaded by

Anonymous zrBShg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

<RelativeLayout xmlns:android="[Link]

com/apk/res/android"
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<Button
android:id="@+id/simpleButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:background="#00f"
android:drawableRight="@drawable/ic_launcher"
android:hint="AbhiAndroid Button1"
android:padding="5dp"
android:textColorHint="#fff"
android:textSize="20sp"
android:textStyle="bold|italic" />

<Button
android:id="@+id/simpleButton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#f00"
android:drawableLeft="@drawable/ic_launcher"
android:hint="AbhiAndroid Button2"
android:padding="5dp"
android:textColorHint="#fff"
android:textSize="20sp"
android:textStyle="bold|italic" />

</RelativeLayout>
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {

Button simpleButton1, simpleButton2;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
simpleButton1 = (Button) findViewById([Link].simpleButton1);//get id of
button 1
simpleButton2 = (Button) findViewById([Link].simpleButton2);//get id of
button 2

[Link](new [Link]() {
@Override
public void onClick(View view) {
[Link](getApplicationContext(), "Simple Button 1", To
ast.LENGTH_LONG).show();//display the text of button1
}
});
[Link](new [Link]() {
@Override
public void onClick(View view) {
[Link](getApplicationContext(), "Simple Button 2", To
ast.LENGTH_LONG).show();//display the text of button2
}
});
}

You might also like