如何坚持在整个活动中的Android视图 [英] How to persist a View across Activities in Android
问题描述
我工作的一个Android应用程序,我想保持各种各样的顶级酒吧,我的大部分活动,具体根据Twitter和Facebook应用程序。这是怎么做的?我想保持它有在任何时候,因为它会提供的功能核心,整个应用程序。
I'm working on an Android application and I'd like to maintain a top-bar of sorts in most of my Activities, as per the Twitter and Facebook applications. How is this done? I'd like to keep it there at all times, as it'll provide functionality core to the whole application.
推荐答案
打破标题栏出到一个单独的布局,并使用的包括的XML标记。我做了一些我的应用程序。您的每一个活动都可以从包含了包括布局,如事件基本活动继承如果标题栏有按钮。
Break the title bar out into a separate layout, and use the include xml tag. I do that in a few of my apps. Each of your activities can inherit from a Base Activity that contains events for the included layout, e.g. if the title bar has buttons.
以下示例伪code。
title.xml
title.xml
<LinearLayout>
<TextView text="Some text"/><Button text="Some Button" onCLick="buttonClick"/>
</LinearLayout>
活动的布局,每个布局
activity layouts for each layout
<RelativeLayout>
<include layout="@layout/title" />
</RelativeLayout>
BaseActivity
BaseActivity
public class BaseActivity extends Activity {
public void buttonClick(View v) {
// do something interesting.
}
}
public class OtherActivity extends BaseActivity {}
这篇关于如何坚持在整个活动中的Android视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!