related url:http://ezmobile.wordpress.com/2009/02/02/customized-android-tabs/
XMI:
for up:<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<!--<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview1">
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/contactListView">
</ListView>
</LinearLayout>
--><LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview2" ></LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview3"></LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview4"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
for bottom:
<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/bodybg"><TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:layout_gravity="bottom">
<RelativeLayout android:id="@+id/LinearLayout01"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<!--<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview1">
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/contactListView">
</ListView>
</LinearLayout>
--><LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview1" ></LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview2"></LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview3"></LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabview4"></LinearLayout>
</FrameLayout>
</RelativeLayout>
</TabHost></RelativeLayout>
ACTIVITY:
public class StarttabActivity extends TabActivity implements TabContentFactory,
OnTabChangeListener, OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(1);
setContentView(R.layout.montacttab);
TabHost mTabHost = getTabHost();
Resources res = getResources();
Context ctx = this.getApplicationContext();
// TabSpec tabSpec = mTabHost.newTabSpec("tab_test1");
// tabSpec.setIndicator("Map");
// Context ctx = this.getApplicationContext();
// Intent i = new Intent(ctx, MapTabView.class);
// tabSpec.setContent(i);
// mTabHost.addTab(tabSpec);
//
Intent AddBuddyActivity1 = new Intent(this, AddBuddyActivity.class);
Intent AddBuddyActivity2 = new Intent(this, AddBuddyActivity.class);
Intent AddBuddyActivity3 = new Intent(this, AddBuddyActivity.class);
Intent AddBuddyActivity4 = new Intent(this, AddBuddyActivity.class);
mTabHost
.addTab(mTabHost.newTabSpec("0").setIndicator("Buddies",
res.getDrawable(R.drawable.icon)).setContent(
AddBuddyActivity1));
mTabHost
.addTab(mTabHost.newTabSpec("1").setIndicator("Tab2",
res.getDrawable(R.drawable.icon)).setContent(
AddBuddyActivity2));
mTabHost
.addTab(mTabHost.newTabSpec("2").setIndicator("Tab3",
res.getDrawable(R.drawable.icon)).setContent(
AddBuddyActivity3));
// mTabHost.addTab(mTabHost.newTabSpec("travel").setIndicator("Travel").setContent(R.id.tabview4));
// mTabHost.addTab(mTabHost.newTabSpec("3").setIndicator("Travel",res.getDrawable(R.drawable.travelicon))
// .setContent(new Intent(this, TravellistActivity.class)));
mTabHost.addTab(mTabHost.newTabSpec("3").setIndicator("Product",
res.getDrawable(R.drawable.icon_product)).setContent(
AddBuddyActivity4));
// mTabHost.addTab(mTabHost.newTabSpec("4").setIndicator("Visibility",res.getDrawable(R.drawable.iconmap_white))
// .setContent(R.id.tabview4));
mTabHost.setCurrentTab(0);
mTabHost.setOnClickListener(this);
mTabHost.setOnTabChangedListener(this);
}
public View createTabContent(String tag) {
// TODO Auto-generated method stub
return null;
}
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
// displayed when changing tabs
Log.d("LOG_KEY", "OnTabChanged");
}
public void onClick(View v) {
// TODO Auto-generated method stub
// Never Displayed within the LOG output
Log.d("LOG_KEY", "OnClick");
}
}
To set backgound onclick:url:http://groups.google.com/group/android-developers/browse_thread/thread/46c11c89fd7e3e17/e3c73b966fa4243b?lnk=raot
tabindicator.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_focus"/>
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_focus"/>
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_focus"/>
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_focus"/>
<item android:state_pressed="true"
android:drawable="@drawable/tab_press"/>
</selector>
XMI:
for up:<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<!--<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview1">
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/contactListView">
</ListView>
</LinearLayout>
--><LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview2" ></LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview3"></LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview4"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
for bottom:
<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/bodybg"><TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:layout_gravity="bottom">
<RelativeLayout android:id="@+id/LinearLayout01"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<!--<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview1">
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/contactListView">
</ListView>
</LinearLayout>
--><LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview1" ></LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview2"></LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/tabview3"></LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabview4"></LinearLayout>
</FrameLayout>
</RelativeLayout>
</TabHost></RelativeLayout>
ACTIVITY:
public class StarttabActivity extends TabActivity implements TabContentFactory,
OnTabChangeListener, OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(1);
setContentView(R.layout.montacttab);
TabHost mTabHost = getTabHost();
Resources res = getResources();
Context ctx = this.getApplicationContext();
// TabSpec tabSpec = mTabHost.newTabSpec("tab_test1");
// tabSpec.setIndicator("Map");
// Context ctx = this.getApplicationContext();
// Intent i = new Intent(ctx, MapTabView.class);
// tabSpec.setContent(i);
// mTabHost.addTab(tabSpec);
//
Intent AddBuddyActivity1 = new Intent(this, AddBuddyActivity.class);
Intent AddBuddyActivity2 = new Intent(this, AddBuddyActivity.class);
Intent AddBuddyActivity3 = new Intent(this, AddBuddyActivity.class);
Intent AddBuddyActivity4 = new Intent(this, AddBuddyActivity.class);
mTabHost
.addTab(mTabHost.newTabSpec("0").setIndicator("Buddies",
res.getDrawable(R.drawable.icon)).setContent(
AddBuddyActivity1));
mTabHost
.addTab(mTabHost.newTabSpec("1").setIndicator("Tab2",
res.getDrawable(R.drawable.icon)).setContent(
AddBuddyActivity2));
mTabHost
.addTab(mTabHost.newTabSpec("2").setIndicator("Tab3",
res.getDrawable(R.drawable.icon)).setContent(
AddBuddyActivity3));
// mTabHost.addTab(mTabHost.newTabSpec("travel").setIndicator("Travel").setContent(R.id.tabview4));
// mTabHost.addTab(mTabHost.newTabSpec("3").setIndicator("Travel",res.getDrawable(R.drawable.travelicon))
// .setContent(new Intent(this, TravellistActivity.class)));
mTabHost.addTab(mTabHost.newTabSpec("3").setIndicator("Product",
res.getDrawable(R.drawable.icon_product)).setContent(
AddBuddyActivity4));
// mTabHost.addTab(mTabHost.newTabSpec("4").setIndicator("Visibility",res.getDrawable(R.drawable.iconmap_white))
// .setContent(R.id.tabview4));
mTabHost.setCurrentTab(0);
mTabHost.setOnClickListener(this);
mTabHost.setOnTabChangedListener(this);
}
public View createTabContent(String tag) {
// TODO Auto-generated method stub
return null;
}
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
// displayed when changing tabs
Log.d("LOG_KEY", "OnTabChanged");
}
public void onClick(View v) {
// TODO Auto-generated method stub
// Never Displayed within the LOG output
Log.d("LOG_KEY", "OnClick");
}
}
To set backgound onclick:url:http://groups.google.com/group/android-developers/browse_thread/thread/46c11c89fd7e3e17/e3c73b966fa4243b?lnk=raot
tabindicator.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_focus"/>
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_focus"/>
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_focus"/>
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_focus"/>
<item android:state_pressed="true"
android:drawable="@drawable/tab_press"/>
</selector>
No comments:
Post a Comment