片段上的后退按钮

时间:2014-03-19 15:40:54

标签: android fragment android-tabhost back

当我点击后退按钮时,如何翻译片段?

@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();
}

谢谢。

1 个答案:

答案 0 :(得分:2)

将您的代码放入

@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);
}

并将getSupportActionBar().setDisplayHomeAsUpEnabled(true);放入onCreate