问题
In my app, I'm displaying a Toolbar with the home button visible. In some screens this works as an up button, in others not.
That works fine.
Problem is that when importing the design support library, the home button is not shown in the toolbar. This happens just by importing it, not a single line of code changed.
I'm importing it in Gradle with:
compile 'com.android.support:design:22.2.0'
Do I need to change something in code for the design library not to make the home button disappear? Is this another bug in the design library?
Note, I'm also using the support lib like:
compile 'com.android.support:appcompat-v7:22.2.0'
Also, this is how I inflate the 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 up 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, these works perfectly fine until I just import the design
lib in Gradle.
Thank you.
回答1:
I personnaly get the Toolbar
then set it as ActionBar
and use the regular methods and it works for me.
Hope it 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);
来源:https://stackoverflow.com/questions/31475986/home-button-not-shown-when-using-the-design-support-library