简体   繁体   English

片段活动标题栏上的后退按钮意图

[英]Back Button Intent On Title bar of Fragment Activity

How to intent from Fragment Activity Class going to a Fragment Class ? 如何从意图 Fragment Activity Class去一个Fragment Class

the code below that i posted was used in an activity class where in there is a back button on the title bar. 我发布的下面的代码用于一个活动类 ,其中在back button on the title bar.有一个back button on the title bar.

now what i want to do is the same but i want to implement it in an fragment class 现在我想做的是一样的,但是我想implement it in an fragment class

I tried this in my Activity Class.. 我在活动课堂上尝试了这个。

   ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

and also 并且

public boolean onOptionsItemSelected(MenuItem item){
    Intent myIntent = new Intent(getApplicationContext(), LoginActivity.class);
    startActivityForResult(myIntent, 0);
    finish();
    return true;

}

Try this 尝试这个

@Override
    public boolean onOptionsItemSelected(MenuItem item)
    {

        super.onOptionsItemSelected(item);
        int id = item.getItemId();

        switch(id)
        {

        case android.R.id.home:
            // if (page == PAGE_CHILD) finish();
        Intent myIntent = new Intent(getApplicationContext(), LoginActivity.class);
        startActivityForResult(myIntent, 0);
        finish();
            break;

        default:
            break;
        }
        return true;
    }

For fragments u can use 对于碎片,您可以使用

FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.popBackStack();

at the place of Intent. 在意图的地方。

Or replace the fragments 或更换碎片

        LoginScreen firstFragment = new LoginScreen();

        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.article_fragment, firstFragment).commit();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM