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.
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.
Example pseudocode below.
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
public class BaseActivity extends Activity {
public void buttonClick(View v) {
// do something interesting.
}
}
public class OtherActivity extends BaseActivity {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With