I created a scrollable tab bar using tabhost, tabwidget and horizontalscrollbar, which is the bottom layout_gravity. Now I want to create a user API for this, so anyone can use the api to change the text, height, width, etc., According to their requisition.
Tabbar.java
package com.tabbar.project;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TabHost;
public class Tabbar extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, FirstActivity.class);
spec = tabHost.newTabSpec("first").setIndicator("Contact", res.getDrawable(R.drawable.contact_img)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SecondActivity.class);
spec = tabHost.newTabSpec("second").setIndicator("Dial", res.getDrawable(R.drawable.dial_img)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ThirdActivity.class);
spec = tabHost.newTabSpec("third").setIndicator("Movie", res.getDrawable(R.drawable.movie_img)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, FourthActivity.class);
spec = tabHost.newTabSpec("fourth").setIndicator("gellary", res.getDrawable(R.drawable.gellary_img)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, FifthActivity.class);
spec = tabHost.newTabSpec("fifth").setIndicator("Opera", res.getDrawable(R.drawable.opera_img)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SixthActivity.class);
spec = tabHost.newTabSpec("sixth").setIndicator("Contacts", res.getDrawable(R.drawable.contact_img)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SeventhActivity.class);
spec = tabHost.newTabSpec("seventh").setIndicator("Dial", res.getDrawable(R.drawable.dial_img)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, EightActivity.class);
spec = tabHost.newTabSpec("eight").setIndicator("Movie", res.getDrawable(R.drawable.movie_img)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, NinthActivity.class);
spec = tabHost.newTabSpec("ninth").setIndicator("Gellary", res.getDrawable(R.drawable.gellary_img)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, TenthActivity.class);
spec = tabHost.newTabSpec("tenth").setIndicator("Opera", res.getDrawable(R.drawable.opera_img)).setContent(intent);
tabHost.addTab(spec);
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++){
tabHost.getTabWidget().getChildAt(i).getLayoutParams().width = 64;
}
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++){
tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 60;
}
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++){
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#50000000"));
}
tabHost.setCurrentTab(0);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:background="@drawable/zero"
>
<TabHost android:id="@android:id/tabhost" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scrollbars="none">
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"
android:layout_gravity="bottom"
android:tabStripEnabled="false"
/>
</HorizontalScrollView>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabcontent"/>
</TabHost>
</LinearLayout>
manoj source
share