0% found this document useful (0 votes)
2 views3 pages

Practical no 9A

The document outlines a practical assignment to create an Android application with a toggle button to display Bluetooth status (ON/OFF). It includes the XML layout code for the user interface and the Java code for the main activity that handles the toggle button and a click event for a button. When the button is clicked, it shows a toast message indicating the current Bluetooth status based on the toggle button's state.

Uploaded by

Soham Pandit
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)
2 views3 pages

Practical no 9A

The document outlines a practical assignment to create an Android application with a toggle button to display Bluetooth status (ON/OFF). It includes the XML layout code for the user interface and the Java code for the main activity that handles the toggle button and a click event for a button. When the button is clicked, it shows a toast message indicating the current Bluetooth status based on the toggle button's state.

Uploaded by

Soham Pandit
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/ 3

Practical no 9A

1. Write a program to create a toggle button to display ON / OFF


Bluetooth on the display screen.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="186dp"
android:layout_height="101dp"
android:layout_x="97dp"
android:layout_y="196dp"
android:checked="true"
android:drawableTop="@drawable/ic_launcher_foreground"
android:text="ToggleButton"
android:textColor="#009688"
android:textOff="Disable"
android:textOn="Enable"
android:textSize="24sp" />

<Button
android:id="@+id/button"
android:layout_width="163dp"
android:layout_height="66dp"
android:layout_x="128dp"
android:layout_y="387dp"
android:padding="10dp"
android:text="Click here"
android:textColor="#4CAF50"
android:textSize="24sp" />
</AbsoluteLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.exp9a;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Application;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.app.Application;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {


ToggleButton toggle;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toggle=(ToggleButton) findViewById(R.id.toggleButton);
b1 = (Button) findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String message = "Bluetooth:="+toggle.getText();

Toast.makeText(MainActivity.this,message,Toast.LENGTH_SHORT).show();
}
});
}
}
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy