Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android toolbar home button not showing

I am trying to create a toolbar which also have the Home icon/button so that the user can go back to home with it.

This is my code:

AndroidManifest.xml

<activity
            android:name=".SettingsActivity"
            android:noHistory="true"
            android:theme="@style/AppTheme">
        <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity"/>
</activity>

toolbar.xml:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:background="@color/ColorPrimary"
    android:elevation="2dp"
    android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"/>

settings_activity.xml:

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

<include
        android:id="@+id/tool_bar"
        layout="@layout/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"/>
</LinearLayout

SettingsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings_activity);

    toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}

However all I see is the name of my application and no UP/Home button at all?

Can you help me please

like image 565
mp3por Avatar asked Nov 23 '15 22:11

mp3por


1 Answers

Change this:

getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);

with:

getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
like image 115
Michele Lacorte Avatar answered Sep 27 '22 19:09

Michele Lacorte