I am trying to hide NavigationDrawer and ActionBar from fragment.
I have created the following interface and implemented the same in activity
public interface CommonMethodsListener {
void hideActionbar();
void showActionbar();
void setActionBarTitle(String title);
}
I have implemented following methods in Activity.
public void setDrawerEnabled(boolean enabled) {
int lockMode = enabled ? DrawerLayout.LOCK_MODE_UNLOCKED :
DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
drawer.setDrawerLockMode(lockMode);
toggle.setDrawerIndicatorEnabled(enabled);
}
@Override
public void hideActionbar() {
getSupportActionBar().hide();
setDrawerEnabled(false);
}
@Override
public void showActionbar() {
getSupportActionBar().show();
setDrawerEnabled(true);
}
I am calling the hideActionBar()
and showActionBar()
in Fragment as below
@Override
public void onResume() {
super.onResume();
mCommonMethodsListener.hideActionbar();
}
@Override
public void onPause() {
super.onPause();
mCommonMethodsListener.showActionbar();
}
I am having trouble hiding the ActionBar and NavigationDrawer with the above code.
I have two fragments called SplashFragment
and LoginFragment
. I am calling the hideActionBar()
and 'showActionBar()in
onResume()and
onPause()` in both fragments.
The SplashFragment
loads without ActionBar
and NavigationDrawer
. An Handler
with postDelayed
will navigation to LoginFragment
after a preset delay of 3000 mSec.
The LoginFragment
shows up with ActionBar
and NavigationDrawer
.
The build.gradle is as below.
android {
compileSdkVersion 28
defaultConfig {
applicationId "io.azpire.ncloudpay"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation "androidx.room:room-runtime:2.1.0-beta01"
annotationProcessor "androidx.room:room-compiler:2.1.0-beta01"
}