-1

I want to set the navigation icon for my toolbar ,and get into the problem that the icon isn't center inside by default it looks like:


enter image description here

and the code is:


    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true); 
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_48dp);

and the theme.xml is:


    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:navigationBarColor">@color/colorPrimaryDark</item>
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>

and the layout xml is:


<android.support.v7.widget.Toolbar     
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
/>

I think I have tried everything I know but I just can't figure it out.I used to set the navigation icon for toolbar then it will be center inside and now.Any help will save my day!

Eidted: of course I tried different size of icons 24dp 32dp and I konw I could add a custom layout in toolbar or customize a layout like (which is a Linearlayout I write about)


enter image description here


But I just don't why I can't set the navigation icon like before,it will automatically be center inside....I think maybe I should change the theme or define something like navigationButttonStyle in the attributes....

Community
  • 1
  • 1
Sinyuk
  • 277
  • 6
  • 16

3 Answers3

1

I fix this by inherit the right theme Widget.AppCompat.Toolbar rather than ThemeOverlay.AppCompat.Dark.ActionBar to define my own toolbar style. And use

<item name="toolbarStyle">@style/MyToolBar</item>

to set the toolbarStyle

cmicat
  • 347
  • 3
  • 5
0

I think you are using a bit big image. Try figure it out using this link

Jayakrishnan Salim
  • 977
  • 1
  • 10
  • 24
-1

OK now I finally find out where the problem is: which has nothing to do with the icon size


You should place the image resource in the to the corresponding folder like (drawable-xxhdpi , drawable-xhdpi).If you don't do so,which means if you just put it in the drawable folder , it won't be auto resized to be center inside in your toolbar;

Sinyuk
  • 277
  • 6
  • 16