2

I have researched a lot that how can I align the tabs at the bottom of page using this code but I didn't find any content, I am using the code as:

public class MainActivity  extends TabActivity {

    /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
    TabHost tabHost = getTabHost();   

    tabHost.addTab(tabHost.newTabSpec("tab1")
            .setIndicator("Home")
            .setContent(new Intent(this, TabGroup1Activity.class)));

    tabHost.addTab(tabHost.newTabSpec("tab2")
            .setIndicator("Search"/*, getResources().getDrawable(R.drawable.ic_launcher)*/)
            .setContent(new Intent(this, TabGroup2Activity.class))
            );

    tabHost.addTab(tabHost.newTabSpec("tab3")
            .setIndicator("About Us")
            .setContent(new Intent(this, TabGroup3Activity.class)));

     tabHost.getTabWidget().setCurrentTab(0);
    tabHost.getTabWidget().setGravity(Gravity.BOTTOM);

And the TabGroup1Activity is:

public class TabGroup1Activity extends TabGroupActivity{
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startChildActivity("HomeActivity", new Intent(this,HomeActivity.class));
    }
}

By using this code, the tab bar is coming at the top of the screen but I want to place it at the bottom ..Please suggest something and I found this method is quite easy for creating tabs

Cœur
  • 37,241
  • 25
  • 195
  • 267
Kanika
  • 10,648
  • 18
  • 61
  • 81
  • Why do you want it programmatically if you can do it through XML layout? – Paresh Mayani Aug 06 '12 at 11:25
  • Why do you want them at the bottom? The Android design guidelines do not recommend it: http://developer.android.com/design/patterns/pure-android.html – sww314 Aug 06 '12 at 11:40
  • @PareshMayani: But I am not using frame layout here, so how can I do it through XML layout? – Kanika Aug 06 '12 at 11:43
  • check this link it may help u http://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom – shassss Aug 06 '12 at 11:22
  • Try his http://unforsaken24.blogspot.in/2011/01/adding-tabs-in-android-and-placing-them.html – Kishore Aug 06 '12 at 11:29
  • There will be always at least one guy who will ask "Why? Why do you need it?". The OP asked a specific question, not work-arounds. – Arturs Vancans Aug 20 '12 at 15:31

1 Answers1

0
   public void addNewTab(Context context, String title, int height){
  TabHost tabHost = getTabHost();  // The activity TabHost
  Intent intent = new Intent().setClass(context, HelloTabsActivity.class);
  TabHost.TabSpec spec = tabHost.newTabSpec(title.toLowerCase()).setIndicator(title).setContent(intent);
 tabHost.addTab(spec);

int totalTabs = tabHost.getTabWidget().getChildCount();
 ((RelativeLayout)tabHost.getTabWidget().getChildTabViewAt(totalTabs-1)).removeViewAt(0);
 ((TextView)((RelativeLayout)tabHost.getTabWidget().getChildTabViewAt(totalTabs-1)).getChildAt(0)).setHeight(30);
 tabHost.getTabWidget().getChildAt(totalTabs-1).getLayoutParams().height = height;
  }
shassss
  • 321
  • 1
  • 13