3

Hi am developing an android application which has a toolbar and hamburger icon to open drawer. I have written below to implement toolbar.

xml file:

<android.support.v7.widget.Toolbar>

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@color/colorPrimary"

android:minHeight="?attr/actionBarSize">

</android.support.v7.widget.Toolbar>

Java file:

Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
        ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
        ((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        ((AppCompatActivity)getActivity()).getSupportActionBar().setHomeButtonEnabled(true);

When I click on drawer layout, fragment opens and hamburger button changes to back arrow button.

I don't want this back arrow button. I want that irrespective of which fragment is selected there should always be hamburger icon.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
amitmitra
  • 37
  • 1
  • 9

2 Answers2

2

remove this if you don't want any icon:

((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);

If you want to set custom icon then add this:

 ((AppCompatActivity)getActivity()).getSupportActionBar().setHomeAsUpIndicator(R.mipmap.backarrow);
Parsania Hardik
  • 4,593
  • 1
  • 33
  • 33
  • ... Why did you change your code? That line **is in the OP's code**. Now you are recommending removing a line that is not there! If you want to point out the line was wrong to begin with, please do so in an additional comment. – Jongware Aug 21 '16 at 10:54
1

Set your icon in the toolbar, the example is using the default arrow:

mToolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);

And to hide, and show:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Pablo Cegarra
  • 20,955
  • 12
  • 92
  • 110