0

I'm a noob to android development and I am trying to make custom tabs. However, when I run my application the tabs fill the entire height of the screen and for some reason makes the soft keyboard appear during OnCreate. I can't determine whether this is because tabhost is failing to set content, layout inflater has bad parameters, or something else that I am missing. I used this tutorial as my guide, so I don't understand why I am having this issue. Any help is greatly appreciated.

My Code;

inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);        
    th = (TabHost)findViewById(R.id.tabhost);

    calTab = inflater.inflate(R.layout.tab, th.getTabWidget(), false);
    calTab.setLayoutParams(params);
    label = (TextView) calTab.findViewById(R.id.tabLabel);
    label.setText("CALC");
    divider = (TextView) calTab.findViewById(R.id.tabSelectedDivider);
    divider.setVisibility(View.VISIBLE);        

    newsTab = inflater.inflate(R.layout.tab, th.getTabWidget(), false);
    newsTab.setLayoutParams(params);
    label = (TextView) newsTab.findViewById(R.id.tabLabel);
    label.setText("NEWS");

    fdTab = inflater.inflate(R.layout.tab, th.getTabWidget(), false);
    fdTab.setLayoutParams(params);
    label = (TextView) fdTab.findViewById(R.id.tabLabel);
    label.setText("FIND");

    pTab = inflater.inflate(R.layout.tab, th.getTabWidget(), false);
    pTab.setLayoutParams(params);
    label = (TextView) pTab.findViewById(R.id.tabLabel);
    label.setText("PORT");


    th.setup();

    specs1 = th.newTabSpec("tag1");
    specs1.setContent(R.id.tab1);
    specs2 = th.newTabSpec("tag2");
    specs2.setContent(R.id.tab2);
    specs3 = th.newTabSpec("tag3");     
    specs3.setContent(R.id.tab3);
    specs4 = th.newTabSpec("tag4");     
    specs4.setContent(R.id.tab4);
    if(android.os.Build.VERSION.SDK_INT>10){ 
        specs1.setIndicator(calTab);
        specs2.setIndicator(newsTab);
        specs3.setIndicator(fdTab);
        specs4.setIndicator(pTab);
    }else{
        specs1.setIndicator("CAL",getResources().getDrawable(R.drawable.calculatortab));
        specs2.setIndicator("NEWS",getResources().getDrawable(R.drawable.news));
        specs3.setIndicator("FIND ", getResources().getDrawable(R.drawable.maptab));
        specs4.setIndicator("PORT", getResources().getDrawable(R.drawable.portfoliotab));
    }
    th.addTab(specs1);
    th.addTab(specs2);
    th.addTab(specs3);
    th.addTab(specs4); 
    th.setOnTabChangedListener(Activity.this);

TAB XML

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/tabLabel"
    android:layout_width="fill_parent"
    android:layout_height="43dp"
    android:gravity="center_vertical|center_horizontal"
    android:textColor="#FFF"
    android:textSize="12dp"/>

<TextView
    android:id="@+id/tabSelectedDivider"
    android:layout_width="fill_parent"
    android:layout_height="5dp"
    android:layout_alignParentBottom="true"
    android:background="#3366CC"
    android:visibility="gone" />

<TextView
    android:id="@+id/tabDivider"
    android:layout_width="fill_parent"
    android:layout_height="2dp"
    android:layout_alignParentBottom="true"
    android:background="#3366CC" />

<TextView
    android:id="@+id/tabSplitter"
    android:layout_width="1px"
    android:layout_height="23dp"
    android:layout_alignParentRight="true"
    android:layout_marginTop="10dp"
    android:background="#333" />

MAIN XML With TABHOST

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" > <!-- changed from match parent -->

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sat="http://schemas.android.com/apk/res/com.bryanjrichardson.GSCC"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >



            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

...and so forth
B. Money
  • 931
  • 2
  • 19
  • 56

1 Answers1

1

You need to give your tabwidget a definite height. So, Instead of wrap content for the widget height you should enter a value such as 60dp or whatever is aesthetically pleasing.

Mr. Bojangles
  • 348
  • 2
  • 6
  • 15