khouloud mejdoub
khouloud mejdoub

Reputation: 1003

Back button on fragment

How can i translate fragment when i click back button?

@Override
    public void onBackPressed()
    {
        FragmentTransaction ft;
        ft = fm.beginTransaction();
        ft.replace(R.id.fragment_content, new RMBTStartFragment());
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();
}

Thank you.

Upvotes: 0

Views: 123

Answers (1)

user3432220
user3432220

Reputation: 101

put your code into

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.

            if (id == android.R.id.home) {
              // your code
            }
    else if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

and put getSupportActionBar().setDisplayHomeAsUpEnabled(true); in your onCreate

Upvotes: 2

Related Questions