全屏切换

时间:2015-12-09 02:04:37

标签: android togglebutton android-fullscreen android-togglebutton

我想通过切换按钮控制手机的全屏。我做到了,但它只工作一次。我怎么解决它? 有代码:

final ToggleButton toggle_button_for_full_screen = (ToggleButton) findViewById(R.id.toggleButton1);
toggle_button_for_full_screen.setOnCheckedChangeListener(new OnCheckedChangeListener() {
boolean variable_for_saving_toggle_button_status;

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // TODO Auto-generated method stub
        if (isChecked)
            {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
        else
            {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            }
    }
});

1 个答案:

答案 0 :(得分:1)

请尝试使用以下代码执行此操作:

if (isChecked)
            {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            }
        else
            {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }

它对我很好。