Code example for ToggleButton

Methods: setOnCheckedChangeListenersetCheckedsetTextOffsetTextOn

1
public class LockScreenActivity extends Activity {
 
	@Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ToggleButton toggle = new ToggleButton(this);
        setContentView(toggle);
        toggle.setTextOn("LOCKED");
        toggle.setTextOff("Lock");
         
        // 画面の向きをデバイスに任せる設定になっているかどうか調べる 
        if(getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
        	toggle.setChecked(true);
        } else { 
        	toggle.setChecked(false);
        } 
         
        toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override 
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				int current = getResources().getConfiguration().orientation;
				if(isChecked) {
					switch(current) {
Stop searching for code, let great code find you!  Add Codota to your java IDE