Android: how to hide title bar on button click

混江龙づ霸主 提交于 2019-12-24 19:39:54

问题


App crashing when using requestWindowFeature(Window.FEATURE_NO_TITLE);

When using the button to make it full screen which when tries to hide the Title bar the app crashes

static int vari = 0;
public void fsc(){
    ib = (ImageButton) findViewById(R.id.fulls);
    ib.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "Full-Screen", Toast.LENGTH_LONG).show();
            if(vari == 0)
            {
requestWindowFeature(Window.FEATURE_NO_TITLE);
   getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                    vari = 1;

            }
        });

I wanted to make it full screen (hiding both status and title bar) on the button press

Please note: this is also to be called to fragments


回答1:


Check if you have the fullscreen theme set in the manifest?

//if not add this in your manifest

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

// Hide status bar

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

// Show status bar

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);



来源:https://stackoverflow.com/questions/54583904/android-how-to-hide-title-bar-on-button-click

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