androidandroid-actionbarandroid-toolbarandroid-4.1-jelly-bean

Up arrow missing from 4.1 Toolbar


I've got a custom toolbar set up. But for some reason, on 4.1 the up arrow asset won't show. The touch area is still there and it works, but the asset won't show up.

Here's the code that creates the toolbar. (The toolbar is set elsewhere in my base activity)

public ActionBar(AppCompatActivity activity) {
    Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
    toolbar.findViewById(R.id.header_layout).setVisibility(View.GONE);

    actionBar = activity.getSupportActionBar();
    savedDisplayOptions = actionBar.getDisplayOptions();
    savedTitle = actionBar.getTitle();
    actionBar.setDisplayShowCustomEnabled(false);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeAsUpIndicator(R.drawable.up_button);
    actionBar.setDisplayShowHomeEnabled(false);
}

Here's the buttons xml. As you can see I have a fix for a bug with the action bar in 4.1 (I've tried removing this to no avail)

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:left="@dimen/double_spacing"
    android:right="@dimen/double_spacing">
    <shape>
        <size android:height="@dimen/standard_icon_size" android:width="@dimen/standard_icon_size"/>
        <!-- DO NOT REMOVE, this fixes a bug on 4.1 where the background defaults to black -->
        <solid android:color="@color/transparent"/>
    </shape>

</item>
<item
    android:left="@dimen/double_spacing">
    <bitmap android:src="@drawable/ic_up_arrow" android:gravity="left"/>
</item>

Finally here's what my toolbar looks like.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/action_bar_height"
    android:elevation="@dimen/half_spacing"
    app:theme="@style/ToolbarTheme"
    android:background="@color/white"
    tools:ignore="UnusedAttribute">

   <com.mypackage.core.view.TextView
       android:id="@+id/standard_toolbar_title"
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
       android:ellipsize="end"
       android:maxLines="1"
       style="@style/H5.Blue" />

    <com.mypackage.util.graphics.ActionBarView
        android:id="@+id/max_header_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"/>

</android.support.v7.widget.Toolbar>

Fun thing I just discovered. If I remove the gravity attribute from the bitmap in the up_button xml, the arrow appears, but greatly stretched. If I then remove the transparent item, it vanishes again.


Solution

  • Looks like it was the old hack itself. After removing it and just pointing directly to the asset, all was well.