MAD microproject
MAD microproject
INDEX
1
CLICKING ON TOGGLE BUTTON
INTRODUCTION
A toggle button allows the user to change a setting between two states. You can add a basic
toggle button to your layout with the Toggle Button object. Android 4.0 (API level 14) introduces
another kind of toggle button called a switch that provides a slider control, which you can add
with a Switch object.
Toggles may replace two radio buttons or a single checkbox to allow users to choose between
two opposing states
2
CLICKING ON TOGGLE BUTTON
<ToggleButton
android:id="@+id/toggle" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_marginTop="40dp"
android:drawableStart="@drawable/selector"android:textColor="#455A64"
android:textOff="switch_off" android:textOn="switch_on"
tools:ignore="TextContrastCheck" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"android:id="@+id/imageview"
android:layout_marginTop="20dp" android:contentDescription="todo"/>
</LinearLayout>
3
CLICKING ON TOGGLE BUTTON
SELECTER.XML
4
CLICKING ON TOGGLE BUTTON
SWITCH_OFF.XML
5
CLICKING ON TOGGLE BUTTON
SWITCH_ON.XML
6
CLICKING ON TOGGLE BUTTON
MAINACTIVITY.JAVA
package com.example.togglebutton;
import androidx.appcompat.app.AppCompatActivity;import
android.os.Bundle;
import android.os.TokenWatcher; import
android.view.View; import
android.widget.ImageView;
import android.widget.ToggleButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
togglebutton=findViewById(R.id.toggle);
imageview=findViewById(R.id.imageview);
imageview.setImageDrawable(getResources().getDrawable(R.drawable.switch_off));
togglebutton.setOnClickListener(new
View.OnClickListener(){
public void onClick(View View)
{
if (togglebutton.isChecked()) {
imageview.setImageDrawable(getResources().getDrawable(R.drawable.switch_on));
}
else {
7
CLICKING ON TOGGLE BUTTON
imageview.setImageDrawable(getResources().getDrawable(R.dr
awable.switch_off));
}
});
}
}
8
CLICKING ON TOGGLE BUTTON
OUTPUT
9
CLICKING ON TOGGLE BUTTON
10
CLICKING ON TOGGLE BUTTON
CONCLUSION
A toggle button allows the user to change a setting between two states. By this button we
can change the images on the mobile. In mobile This button issued as Switch on / off button
11
CLICKING ON TOGGLE BUTTON
REFERANCE
• https://developer.android.com/android/widget/ToggleButton
• https://developer.android.com/guide/topics/ui/controls/togglebutton
• Text book of Mobile application
12