Freeze screen orientation

前端 未结 3 1949
心在旅途
心在旅途 2021-01-22 13:52

There is CheckBox with following code:

    CheckBox cb = (CheckBox)findViewById(R.id.freezer);
    cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChan         


        
3条回答
  •  长情又很酷
    2021-01-22 14:42

    Since you know how to get the current orientation, just write

    if(isChecked){
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
    

提交回复
热议问题