SetDisplayHomeAsUpEnabled shows arrow instead of left brochure

I want to show the Up button in my activity, the functionality works fine, but I am unable to display the left caret. Instead, an ugly back arrow appears. I do this in my activity -

public class SecondActivity extends ActionBarActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    setTitle(getString(R.string.second));
    mToolbar.setTitleTextColor(getResources().getColor(android.R.color.white));

    ....
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ....

   }
}

      

But I can only see it -

Back arrow

This is the xml layout -

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="org.step.main.SecondActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/listsecond"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="?attr/actionBarSize"
        android:clipToPadding="false"
        tools:context=".SecondActivity"
        />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"/>

</FrameLayout>

      

Any suggestions? Also, is there a way to change the color of the back button to white?

Note. I am using theme -Theme.AppCompat.Light.NoActionBar

+3


source to share


1 answer


Following this answer , you can make any icon display as white.

For the left karat icon, see this answer , which describes where to find it in the Action Icon Pack you will need to download.

Edit: The icons you want are located in Action Bar Icons/holo_dark/02_navigation_previous_item/

To display the left arrow in white, you do the following:



    mToolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //Add the following code to make the up arrow white:
    final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    upArrow.setColorFilter(getResources().getColor(android.R.color.white), PorterDuff.Mode.SRC_ATOP);
    getSupportActionBar().setHomeAsUpIndicator(upArrow);

      

Please note that you need to add this import data:

import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;

      

+8


source







All Articles