ToggleButton selected, unchecked, and you need to set different display text for different states. Property: Checked= "true" textoff= "" texton= ""Private ToggleButton TB ;Private ImageView IV ;TB= (ToggleButton) Findviewbyid (r.id.ToggleButton1); IV= (ImageView) Findviewbyid (r.id. ImageView1); //Set listener for ToggleButton TB. Setoncheckedchangelistener ( New Oncheckedchangelistener () { @Override Public void oncheckedchanged (Compoundbutton Buttonview, Boolean isChecked) { /** When the TB is clicked, the current method is executed* Buttonview represents the skill of the clicked Control (object)* IsChecked represents the status of the clicked Control (on/off) */ IV. Setimageresource (isChecked? R.drawable. on: r.drawable.Ic_launcher); } }); <ToggleButton Android:id="@+id/togglebutton1" Android:layout_width="Match_parent" Android:layout_height="Wrap_content" Android:texton="@string/texton" Android:textoff="@string/textoff" Android:hint="@string/togglebutton" /> <ImageView Android:id="@+id/imageview1" Android:layout_width="Match_parent" Android:layout_height="200DP" android:src="@drawable/ic_launcher" />
Android Multi-Status button ToggleButton