Home button not showing when using the Design Support Library

In my application, I am showing a toolbar with a home button. On some screens this works like an up button, on others it doesn't.

This works great.

The problem is when importing a design support library, the home button is not showing in the toolbar. This only happens by import, not with a single line of code.

I am importing it into Gradle with:

compile 'com.android.support:design:22.2.0'

      

Do I need to change something in the code for the design library so that the home button is not disabled? Is this another mistake in the design library?

Note I also use lib support, for example:

compile 'com.android.support:appcompat-v7:22.2.0'

      

Also, I inflate Toolbar

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- toolbar -->
    <FrameLayout
        android:id="@+id/toolbarContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">

        <include layout="@layout/include_toolbar" />

    </FrameLayout>

    [....]
</RelativeLayout>

      

This is how I set the home button in one Fragment

.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup         
          [....]
          final Toolbar toolbar = (Toolbar)           
          view.findViewById(R.id.toolBar);
          toolbar.setTitle(R.string.foo);
          toolbar.setNavigationIcon(R.drawable.bar);
          [....]
    }

      

As said, they work fine until I just import the design

lib into Gradle.

Thank.

+1


source to share


1 answer


I personally get it Toolbar

, then install it like I ActionBar

use normal methods and it works for me.

Hope this helps you:



final Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolBar);
toolbar.setTitle(R.string.foo);
toolbar.setNavigationIcon(R.drawable.bar);
setSupportActionBar(toolbar);

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

      

0


source







All Articles