SleepNot
SleepNot

Reputation: 3038

ActionBar Back Arrow/Button not appearing

I am switching between my fragments using:

FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.main, Fragment.instantiate(MainActivity.this, fragments[pos]));
tx.addToBackStack("tag");
tx.commit();

But when I do switch fragments, the back button or left caret is not appearing on my action bar. I have set

getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);

on the main activity but still doesnt work.

Am I placing the 2 previous lines of code in the wrong place or class? Or is it my navigation from fragment to another fragment that is not showing the left arrow/caret?

Upvotes: 1

Views: 6902

Answers (1)

Vetalll
Vetalll

Reputation: 3700

What do you use for ActionBar ?

If you use ActionBarSherlock your activity should be like this:

public class MyActivity extends SherlockFragmentActivity{
    //CODE
} 

If you use AppCompat from Google your activity should be like this:

public class MyActivity extends ActionBarActivity {
    //CODE
} 

in your activity for enabling home button you should use :

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);

Upvotes: 6

Related Questions