For my app, I am trying to put buttons at the bottom of all activities similar to WeChat app as can be seen in below image:
Now one way I thought of is simply adding <ImageButton>
s at bottom of each activities but I don't think WeChat does that because you can swipe between activities and there is no onCreate
triggered, activities are always there that are simply switched when swiped or touched on specific button.
I did research and found out one can use split action bar
or even ViewFlipper
. Action bar splitting is out of question since button will be moved back to action bar for example in landscape mode since I want to have buttons always appear at bottom like WeChat. Another option I saw was Tabbed
interface but I saw with it, it can appear below actionbar unlike WeChat where even actionbar is changed based on activity.
Question: Does anyone know what does WeChat use for this functionality so I can implement the same ?
here is code main class
public class TabSample extends TabActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTabs();
}
private void setTabs() {
addTab("Wechat", R.drawable.tab_home, ShowList.class);
addTab("Social", R.drawable.tab_search, UploadVideo.class);
addTab("Contact Us", R.drawable.tab_home, Contactus.class);
addTab("Setting", R.drawable.tab_search, DoNotDo.class);
}
private void addTab(String labelId, int drawableId, Class<?> c) {
TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(
R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
}
here is xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:background="#ffffff"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_weight="0" />
</LinearLayout>
</TabHost>