Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you tested your app on a device running Ice Cream Sandwich? I noticed recently, that the default <code>TabHost</code> behaves differently depending on the target device and the android platform version. </p> <p>Running an app that provides an icon and a text to <code>setIndicator</code> (as in the source from the question), had the following test result:</p> <ul> <li>Phone with Android 2.1: both icon and text where shown (Label below the Icon as expected)</li> <li>Phone with 4.0.3: The icons didn't show and <strong>only the text</strong> was visible.</li> <li>Tablet running ICS: the tabs where shown with icon and text</li> </ul> <p>As you found out too, replacing the label with an <strong>empty string</strong> the <strong>icons appeared</strong> on the Phone - but then the user would need to guess the meaning of the icons. Apart from that: When running this version of the app on the pre ICS phone: The tabs keep their size and leave an empty area below the image.</p> <p>To change this device driven decision on how much space the tabs should get, I found the solution in this <a href="http://ondrejcermak.info/en/programovani/custom-tabs-in-android-tutorial/" rel="noreferrer">tutorial on how to customize tabs</a>: </p> <p>First you need to provide your <strong>own tab indicator</strong> layout ("layout/tab_indicator.xml" in the tutorial) including an <code>ImageView</code> and a <code>TextView</code>. Then you tell the <code>TabSpec</code> to use this via <code>setIndicator</code>. And voilà: you get the icon and the label on the phone with ICS too.</p> <p>Here is the important part on how to set up the indicator (this = the current activity):</p> <pre><code>TabHost.TabSpec spec = this.getTabHost().newTabSpec(tag); View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false); ((TextView) tabIndicator.findViewById(R.id.title)).setText(label); ((ImageView) tabIndicator.findViewById(R.id.icon)).setImageResource(drawableResourceId); spec.setIndicator(tabIndicator); </code></pre> <p>If you like the same look of the tabs on older and newer phones have an additional look here: <a href="http://jgilfelt.github.com/android-actionbarstylegenerator/" rel="noreferrer">http://jgilfelt.github.com/android-actionbarstylegenerator/</a>. This page generates images and styles to customize the action bar including the tabs and helped me figure out how the 9-patch background images need to be defined.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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