toolbar is not hiding in android activity

Viewed 91

i have an activity which contains a Video View from YouTube and we want that when someone rotate phone , toolbar should hide . actually we have rotation lock in our app , so no activity can get rotate except this video containing activity . and i am rotating screen using onConfigurationChange .

i have implmented custom toolbar in that activity and when configuration change and code changes position of screen it should get hide or show , but it is not working .

i am using this code to hide toolbar

getSupportActionbar.hide()

well , i have some doubts about this that why does it is not working :

1 . first when configuration changes , activity creates from the scratch so command for hide toolbar gets overwrite and shoes

2 . i saw somewhere that getSupportActionbar.hide() should come before , setContentView()

here is the code snippet of onConfigurationChange

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        try {
            super.onConfigurationChanged(newConfig);
            int accelometerState = android.provider.Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
            if (accelometerState == 1) {
                if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
//                    toolbar.setVisibility(View.GONE);
//                    getSupportActionBar().hide();
                    isRotate = true;
                }
                if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
//                    toolbar.setVisibility(View.VISIBLE);
//                    getSupportActionBar().show();
                    isRotate = false;
                }
            } else {
                if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            }
        } catch (Exception ex) {
            Log.e("home", "something went wrong in the VideoViewFullScreen.java");
        }
    }

i am trying to figure out what is the problem here ,

if anyone has some solution or suggestion i appreciate them . Thank You in advance

1 Answers

Well in this case you can define a separate layout for the landscape mode using orientation qualifiers in the layout resource files. Learn more.

Related