正确的方法来推动与动作条视图 [英] Correct way to push a view with actionBar

查看:119
本文介绍了正确的方法来推动与动作条视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新的Andr​​oid开发人员,所以我preFER询问正确的方式,以便解决我的问题。

I am an new Android developer so I prefer ask about the correct way so solve my problem.

我有一个FragmentActivity和多个片段,片段我的一个组成是应该按钮,显示像iOS上的导航CONTROLER推新观点看法。

I have a FragmentActivity and multiple fragments, one of my fragment is compose of button supposed to show new view like a push view in a navigation controler on iOS.

我试图创建新的活动,并与一个Intent显示出来,但动作条disseapeared。

I tried to create new activity and display them with an Intent, but the actionBar disseapeared.

那么,要我想创建一个带有动作条工作,让我的行动吧?

感谢您提前。

推荐答案

我会回答我自己,因为我找到了解决方案,也许会有所帮助。
我将比较到iOS。

I will answer myself since I find the solution, maybe it will help. I will compare to iOS.

如果您正在使用的ActionBar工作具有片段,并要打开一个新的观点有2不同的方式。

If you are working with an actionBar possessing fragment, and you want to open a new view there is 2 different way.

如果你想在动作条和所有其他的元素添加一个新的视图,创建一个新的活动和使用意向。
此方法类似于iOS上的模态视图

If you want to add a new view over the actionBar and all other the element, create a new Activity and use Intent. This method is like modal view on iOS

Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
myIntent.putExtra("key", value); //Optional parameters
CurrentActivity.this.startActivity(myIntent);

如果你想在动作条中添加一个新的视图,创建一个新片段,并使用此code:

If you want to add a new view within the ActionBar, create a new Fragment and use this code :

    Fragment newFragment = new MyNewFragmentClass();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();

    // Replace whatever is in the fragment_container view with this fragment,
    // and add the transaction to the back stack
    transaction.replace(R.id.my_current_layout, newFragment);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    transaction.addToBackStack(null);

    // Commit the transaction
    transaction.commit();

这篇关于正确的方法来推动与动作条视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆