0% found this document useful (0 votes)
8 views4 pages

PTR 9

Brhtgehjyrgfeg

Uploaded by

Priti Mane
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)
8 views4 pages

PTR 9

Brhtgehjyrgfeg

Uploaded by

Priti Mane
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
You are on page 1/ 4

<?xml version="1.0" encoding="utf-8"?

>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="20dp">

<Button

android:id="@+id/simpleButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Click Me" />

<ToggleButton

android:id="@+id/toggleButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textOn="Toggle ON"

android:textOff="Toggle OFF" />

<ImageButton

android:id="@+id/imageButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@android:drawable/ic_menu_camera"

android:contentDescription="Camera Button"
android:background="?android:attr/selectableItemBackgroundBorderless"/>

</LinearLayout>

Java file

package com.example.buttondemo;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.ImageButton;

import android.widget.Toast;

import android.widget.ToggleButton;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

Button simpleButton;

ToggleButton toggleButton;

ImageButton imageButton;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

simpleButton = findViewById(R.id.simpleButton);
toggleButton = findViewById(R.id.toggleButton);

imageButton = findViewById(R.id.imageButton);

simpleButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(MainActivity.this, "Simple Button Clicked",


Toast.LENGTH_SHORT).show();

});

toggleButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if (toggleButton.isChecked()) {

Toast.makeText(MainActivity.this, "Toggle is ON", Toast.LENGTH_SHORT).show();

} else {

Toast.makeText(MainActivity.this, "Toggle is OFF", Toast.LENGTH_SHORT).show();

});

imageButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(MainActivity.this, "Image Button Clicked",


Toast.LENGTH_SHORT).show();
}

});

You might also like