Android Show Activity Title/status bar at the top after it is hidden

后端 未结 2 412
北恋
北恋 2021-01-12 17:59

Currently in my FragmentActivity, I hide the status bar by, in the onCreate method, doing the following:

 requestWindowFeature(Wind         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 18:16

    Here you can change your title bar dynamically using following two methods. I called them from my Activity. So to call from Fragment you need the Activity instance.

    public void hideTitle() {
            try {
                ((View) findViewById(android.R.id.title).getParent())
                        .setVisibility(View.GONE);
            } catch (Exception e) {
            }
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().clearFlags(
                    WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        }
    
        public void showTitle() {
            try {
                ((View) findViewById(android.R.id.title).getParent())
                        .setVisibility(View.VISIBLE);
            } catch (Exception e) {
            }
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    

提交回复
热议问题