Write a Program to create a 1 rounded corner image button and 1 normal image button and on the click of the button it should display which button is pressed .

XML Code:

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

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

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".Main20Activity">

    <ImageButton

        android:id="@+id/ib1"

        android:layout_width="250dp"

        android:layout_height="250dp"

        android:layout_x="74dp"

        


android:layout_y="21dp"        android:background="@drawable/round_button"

        android:scaleType="centerInside"

        android:src="@drawable/bts" />

    <ImageButton

        android:id="@+id/ib2"

        android:layout_width="236dp"

        android:layout_height="221dp"

        android:layout_x="83dp"

        android:layout_y="301dp"        android:background="@drawable/round_button"

        android:scaleType="centerCrop"

        android:src="@drawable/exo" />

</AbsoluteLayout>


Java Code:

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.ImageButton;

import android.widget.Toast;

public class Main20Activity extends AppCompatActivity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main20);

        ImageButton ib1=findViewById(R.id.ib1);

        ImageButton ib2=findViewById(R.id.ib2);

        ib1.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {               Toast.makeText(Main20Activity.this, "You have selected Bts", Toast.LENGTH_SHORT).show();

            }

        });

        ib2.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {                Toast.makeText(Main20Activity.this, "You have selected Exo", Toast.LENGTH_SHORT).show();

            }

        });

    }

}



Output:

 



Comments

Popular posts from this blog

Write a program to create a first display screen on any search engine using auto complete text View

Write a Program to create a toggle button to display the ON/OFF Bluetooth on the display screen.

Write a program to create a login form for social networking website.