不同活动之间的分享动作条不同、动作

2023-09-12 02:56:58 作者:一个有趣的妞

我有一个 FragmentActivity 名为 MainActivity 持有两个片段,一个菜单的片段向左和应用一个内容片段到右侧。在一个大的设备这两个片段被示出。上的小设备只有菜单片段被示出并当用户presses在所述菜单中的内容片段中显示一个新的活动的项目

I have an application with an FragmentActivity called MainActivity which holds two fragments, one menu fragment to the left and one content fragment to the right. On a large device both of these fragments are shown. On a small device only the menu fragment is shown and when the user presses an item in said menu the content fragment is displayed in a new Activity.

让我们说的用户当前正在使用他的电话中的应用,只有菜单可见:

Lets say the user is currently using the application on his phone and only the menu is visible:

动作条 MainActivity 可以由用户选择的菜单进行操作。当用户选择一个特定的菜单项,一个新的活动启动要显示的内容片段。当此活动弹出的动作条活动的是一个新的动作条,因此没有类似于动作条 FragmentActivity MainActivity )。

The ActionBar of MainActivity can be manipulated by user choices in the menu. When the user selects a specific menu item, a new Activity launches to display the content fragment. When this Activity pops up the ActionBar of this new Activity is a new ActionBar and therefore does not resemble the ActionBar of FragmentActivity (MainActivity).

我想我可以通过动作条 MainActivity 活动它通过意图其他显示内容片段,或使动作条的静态和引用它像 MainActivity.actionBar 或类似的,但我很快就遇到了麻烦:)

I figured I could pass the ActionBar from MainActivity to the Activity which displays the content fragment through Intent extras, or making the ActionBar static and reference it like MainActivity.actionBar or similar, but I ran into problems very quickly :)

在如何解决这个有什么建议?基本上,我要的是分享我的所有活动之间的单个动作条引用。

Any suggestions on how to solve this? Basically, what I want is to share a single ActionBar reference between all my activities.

推荐答案

也许这是最好用的片段,而不是活动。我的意思是显示菜单片段,当你需要显示内容片段只是把内容片段进位(容器)在那里有菜单片段。我认为更好的/更容易组织片段替换/修改逻辑不是尝试不同的活动之间共享动作条。

Maybe it's better to use fragments instead of activities. I mean show menu fragment, and when you need to show content fragment just put content fragment into the place (container) where was menu fragment. I think better/easier to organize fragment replace/change logics than trying to share actionbar between different activities.

 
精彩推荐
图片推荐