Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The view which represents each tab can be changed using</p> <pre><code>setIndicator(View) </code></pre> <p>I've been using this code to build each tab :</p> <pre><code>View view = buildTabView(this, "Friday"); TabHost.TabSpec spec = tabHost.newTabSpec("cat1").setIndicator(view).setContent(intent); tabHost.addTab(spec); public static LinearLayout buildTabView(Context context, String label){ LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final LinearLayout ll = (LinearLayout)li.inflate(R.layout.tab, null); // the following lines will change the tabs size depending on the label (text) length. // the longer tab text - the wider tabs LinearLayout.LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, label.length() + 1); ll.setLayoutParams(layoutParams); final TextView tv = (TextView)ll.findViewById(R.id.tab_tv); tv.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { ll.onTouchEvent(event); return false; } }); tv.setText(label); return ll; } </code></pre> <p>And here comes layout/tab.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/tab_bg_selector" android:clickable="true" &gt; &lt;TextView android:id="@+id/tab_tv" android:layout_width="wrap_content" android:layout_height="33dip" android:text="Text 1" android:textStyle="bold" android:textSize="16dip" android:gravity="center" android:textColor="@drawable/tab_color_selector" android:layout_weight="1.0" android:clickable="true" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Note that LinearLayout has a selector on it's background (to change backround, obviously :) ), and the TextView has a selector on the textColor (to change the text color when selected / pressed etc.). It this way you can make the text look black when tab is pressed, and white when it is not :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload