android Exit from full screen mode

你说的曾经没有我的故事 提交于 2019-11-27 20:41:34

As per below code, i can hide the TitleBar by your needs,

Button full;
static int vari = 0;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    full = (Button)findViewById(R.id.fullview);
    full.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(vari == 0)
            {
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                vari = 1;
            }else 
            {
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);                 
                vari = 0;
            }

        }
    });
}

Try this code. It helps you lot.

To disable full screen:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
ActivitiesCurrentContentView.requestLayout();

To re-enable full screen:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
ActivitiesCurrentContentView.requestLayout();

I think the key in your case is re-requesting the layout.

From ICS when the Fragment is attached to the Activity, the FULL Screen mode is reseted. The best approach is to add the code

getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getActivity().findViewById(R.id.root).setSystemUiVisibility(View.STATUS_BAR_HIDDEN);

in the callback onActivityCreated of the fragment(layout id root is the root layout of the Activity).

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