【问题标题】:How to start fragment using action bar?如何使用操作栏启动片段?
【发布时间】:2014-10-01 04:09:04
【问题描述】:

这是我的 HomeFragment,我只是想问一下,如果我点击购物车操作栏 CartFragment 就会开始出现。

        case R.id.action_shoppingcart:

        Toast.makeText(this, "shopping cart selected", Toast.LENGTH_SHORT)
                .show();

        return true;

here's my screenshot of menu with actionbar

【问题讨论】:

    标签: android android-actionbar fragment


    【解决方案1】:

    您的问题并不完全清楚,但我会尝试回答。假设您在活动 XML 的框架中定义了当前片段,您只需要在该框架中切换片段。

    Fragment fragment = new CartFragment();
    // Insert the fragment by replacing any existing fragment
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction()
                   .replace(R.id.fragment_frame, fragment)
                   .commit();
    

    【讨论】:

    • 谢谢你的回答,你救了我。
    • @paulbuscano 哈哈!不客气。欢迎来到stackoverflow。下次请不要使用大写字母,但是你很努力,与 SO 社区相处得不好! ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-13
    相关资源
    最近更新 更多