Move up navigation icon in toolbar to the right

1.7k Views Asked by At

I've implemented up navigation to my Navigationdrawer activity.

private void setupActionBar() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}

But it doesnt sho up, I guess it's covered by the icon for opening the navigation drawer.

Question:

How can I position the up navigation icon either next to the drawer activity or on the right of the toolbar?icon

2

There are 2 best solutions below

0
rafsanahmad007 On BEST ANSWER

Try below code: to add your custom Back arrow icon in actionbar Right side...

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(actionBar.getDisplayOptions()
        | ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView imageView = new ImageView(actionBar.getThemedContext());
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(R.drawable.your_back_icon);
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
        ActionBar.LayoutParams.WRAP_CONTENT,
        ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
                | Gravity.CENTER_VERTICAL);
layoutParams.rightMargin = 50;
imageView.setLayoutParams(layoutParams);
actionBar.setCustomView(imageView);
4
Valentin Gavran On

You should not display a UP Button and a Navigation Drawer Icon in Android at the same time. That is also the reason it is not possible for you to achieve this so easylie.

A few years ago Google released the Material Design Guidlines with Material Design to achieve that developers develop apps that feel the same and behave the same like all other. The user should always know how to navigate through your app.

I don't know how you designed your Application but you should only use the UP Button if you want to navigate from a opend Activity to the previous Activity.

I recommend to read the Navigation Guidelines from Google to better understand what I mean.

I hope, that i helped you.