3

I want to show a Up button in my activity, the functionality is working fine, but am unable to get the left caret to show. It instead shows an ugly back arrow. I am doing 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 am only seeing this -

Back Arrow

This is the layout xml -

<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 back button be white?

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

Sam
  • 4,302
  • 12
  • 40
  • 74

1 Answers1

11

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

As for the left carat icon, take a look at this answer, which describes where to find it in the Action Bar Icon Pack which you will need to download.

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

For showing the left arrow white, you would do this:

    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);

Note that you'll need to add these imports:

import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
Community
  • 1
  • 1
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
  • This works for changing the color to white. But my major issue is showing left caret. Is there any pre-specified drawable for that or do I need to create my own? – Sam May 21 '15 at 18:06
  • @Sam I just updated the answer, download the Action Bar Icon Pack,, and the linked answer explains where to find them. http://developer.android.com/design/downloads/index.html – Daniel Nugent May 21 '15 at 18:08
  • I downloaded and added ic_action_previous_item from holo_dark theme from the action pack which is the white image. Thanks. – Sam May 21 '15 at 18:20
  • @Sam I saw that too. Updated the answer, just in case this can help other people in the future! – Daniel Nugent May 21 '15 at 18:22