Search code examples
androidandroid-actionbar

Action Bar Back Button is not showing in Android


Hi I have created an activity which extends ActionBarActivity & using material theme in my application. In the Action Bar, Back button is not showing.

I didn't find why it is not showing. Any help ?

public class RegistrationActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration);

        getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_background_light));
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!--Support Library compatibility-->
    <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

<!-- ActionBar styles -->
<style name="MyTheme.ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar">
    <!--Support Library compatibility-->
    <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@android:color/white</item>
</style>

AndroidManifest.xml

    <activity
        android:name=".RegistrationActivity"
        android:label="@string/title_activity_registration" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".HomeScreenActivity" />
    </activity>

Thanks in advance.


Solution

  • add the property

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    

    to show the "back button"