How to use Toggle button in Android app layout?

Published: 26 April 2024
on channel: Programmer World
111
8

In this video it shows how to use toggle button in an Android app layout.

I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: [email protected]

Complete source code and other details/ steps of this video are posted in the below link:
https://programmerworld.co/android/ho...

However, the main Java code is copied below also for reference:


package com.programmerworld.togglebuttoninandroidapp;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.ToggleButton;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {
private TextView textView;
private ToggleButton toggleButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) - {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);

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

return insets;
});
}

public void buttonOnclick(View view){
textView.setText(toggleButton.getText());
}
}


--


On this page of the site you can watch the video online How to use Toggle button in Android app layout? with a duration of hours minute second in good quality, which was uploaded by the user Programmer World 26 April 2024, share the link with friends and acquaintances, this video has already been watched 111 times on youtube and it was liked by 8 viewers. Enjoy your viewing!