Fullscreen switching

北战南征 提交于 2019-12-12 04:45:43

问题


I want to control a full screen of the phone with toggle button. I did it, but it works only once. How i can fix it? There is code:

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:


Try below code for to do this:

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);
            }

It work fine with me.



来源:https://stackoverflow.com/questions/34169570/fullscreen-switching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!