I am making an application where i need tabs placed at the bottom of the screen . I have managed to get to implement the code of tabs but i can't get them to be placed in the bottom of the screen.
Also i don't want any of the tabs to be selected i.e. i just want four tabs to be present at the bottom of the screen and above the tabs there are some image views and buttons.
I have linked the tabs to respective activites but i don't want the tab bar to be functional until the user wants to go and click it.
Till then i just want a normal gui screen with tabs at the bottom with none of them pre selected.
package com.tabs;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class HelloTabWidget extends TabActivity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources()开发者_如何学运维; // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ArtistsActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists_grey)).setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, AlbumsActivity.class);
spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists_grey)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs",res.getDrawable(R.drawable.ic_tab_artists_grey)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
---------- To place tab at the bottom add the below code
<TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff"><RelativeLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"><FrameLayout android:id="@android:id/tabcontent" android:background="@drawable/bg" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@android:id/tabs"/><TabWidget android:id="@android:id/tabs" android:background="@drawable/tab_bar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:cacheColorHint="#fff" android:layout_alignParentBottom="true" android:textStyle="bold"/></RelativeLayout></TabHost>
##
and if yu dont want any tabs to be selected remove tabHost.setCurrentTab(2);
精彩评论