I am using drawer layout as below. So my fragments are attached to frame layout below toolbar. When I show fragment I change home button from humburger to arrow with:
drawerToggle.setDrawerIndicatorEnabled(b);
getSupportActionBar().setDisplayHomeAsUpEnabled(show);
The problem is - when I click arrow button, there is no event for onOptionsItemSelected in activity or in fragment. If i donw use drawerToggle.setDrawerIndicatorEnabled(b);
arrow button will open the navigation drawer. How to fix such behaviour?
Layout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar" />
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/navigation_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start|center_vertical"
android:background="@color/bg_drawer"
android:clickable="true"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="138dip"
android:layout_marginLeft="24dp"
android:layout_marginTop="11dip"
android:adjustViewBounds="true"
android:src="@drawable/ic_drawer_logo" />
<ListView
android:id="@+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:choiceMode="singleChoice"
android:divider="@drawable/drawer_divider"
android:dividerHeight="1dip"
android:footerDividersEnabled="false"
android:listSelector="@drawable/selector"
android:paddingLeft="24dip"
android:paddingRight="24dip" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Navigation drawer set up
public void setUpNavigationDrawer(){
int width = getResources().getDisplayMetrics().widthPixels * 3 / 4;
DrawerLayout.LayoutParams params =
(android.support.v4.widget.DrawerLayout.LayoutParams) navigationHolder.getLayoutParams();
params.width = width;
navigationHolder.setLayoutParams(params);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
drawerToggle = new ActionBarDrawerToggle(
this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close
){
@Override
public void onDrawerOpened(View drawerView){
super.onDrawerOpened(drawerView);
if(!mUserLearnedDrawer){
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(
mContext
);
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
}
invalidateOptionsMenu();
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset){
super.onDrawerSlide(drawerView, slideOffset);
}
@Override
public void onDrawerClosed(View drawerView){
super.onDrawerClosed(drawerView);
if(needToChangePage){
onNavigationDrawerItemSelected(
(int) drawerView.getTag()
);
}
needToChangePage = false;
}
};
if(!mUserLearnedDrawer){
mDrawerLayout.openDrawer(navigationHolder);
}
mDrawerLayout.post(
new Runnable(){
@Override
public void run(){
drawerToggle.syncState();
}
}
);
mDrawerLayout.setDrawerListener(drawerToggle);
}
Switching between Android Navigation Drawer image and Up caret when using fragments tried approach from here, but with same result