0

I am changing the default arrow in the actionbar to a dropdown menu icon. Here is the code for my actionbar:

Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionbar = getSupportActionBar();
    actionbar.setDisplayHomeAsUpEnabled(true);
    actionbar.setHomeAsUpIndicator(R.drawable.menu);

The problem is, the icon has not changed from a back arrow to a menu icon. The menu in drawable is a jpg file, so I don't see why there would be issues using it to replace the back arrow. Any suggestions?

BuffChihuahua
  • 37
  • 2
  • 4

2 Answers2

-1

Try getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); etSupportActionBar().setHomeAsUpIndicator(R.drawable.upbutton);

Here is the source.

Themelis
  • 4,048
  • 2
  • 21
  • 45
  • It didn't appear to do anything at all. I tried changing the drawable I pass to setHomeAsUpIndicator() to other images, but they all had the same outcome. – BuffChihuahua Nov 11 '18 at 23:26
-1

You can use this Code:-

        setSupportActionBar(toolbar);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.back_arrow_icon_drawable);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

and Override this Method :-

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

Hope it will helps you

Kartik Shah
  • 866
  • 5
  • 19