I have three DrawerLayout
for three Activity
. These activities are mostly same (layouts are copy past). Let's call them as activity 1
, activity 2
, activity 3
. activity 1
can start activity 2
, activity 2
can start activity 3
.
Besides I have my custom base activity: SideMenuActivity
.
They are all extends SideMenuActivity
.
There is a button to open a navigation drawer, whose onClickListener
is in SideMenuActivity
:
protected void initSideMenu() {
sideMenuButton = findViewById(R.id.side_menu_icon_clickable);
sideMenu = findViewById(R.id.side_menu);
sideMenu.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
.
.
.
sideMenuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sideMenuButton.startAnimation(buttonClick);
sideMenu.openDrawer(Gravity.LEFT);
Toast.makeText(context, context.getClass().getSimpleName(), Toast.LENGTH_SHORT).show();
}
});
}
I call this function from both 'activity 1', activity 2
and activity 3
. Navigation drawer can be opened in activity 1
and activity 2
but not in activity 3
.
Why does this onClickListener
not work in activity 3
. Does android have a bug or what?
Also the toast message doesn't appear in activity 3
unlike the others.
Here is the DrawerLayout
:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/side_menu"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/menucontent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/appMainBackground"
tools:context=".xxx.xxx.xxx">
<include
android:id="@+id/include2"
layout="@layout/topbar"
app:layout_constraintBottom_toTopOf="@+id/guideline17"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.1184" />
.
.
.
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout>