Tab icon not showing
Asked Answered
D

4

8

I'm trying to do a simple tab app in android with two tabs. My problem is that when I put this code, in the tab, only is shown the text, but no the icons. If I put the text to "" the icon is shown.

Could someone help me? My android version is 4.0.3.

Thanks a lot.

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

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/tabhost"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" >
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

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

        <LinearLayout android:id="@+id/tab1"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <TextView android:id="@+id/textView1"
                android:text="Contenido Tab 1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    </LinearLayout>

        <LinearLayout android:id="@+id/tab2"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <TextView android:id="@+id/textView2"
                android:text="Contenido Tab 2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    </LinearLayout>

     </FrameLayout>
</LinearLayout>
</TabHost>

and the activity code is

public class TabTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Resources res = getResources();

    TabHost tabs=(TabHost)findViewById(R.id.tabhost);
    tabs.setup();

    TabHost.TabSpec spec=tabs.newTabSpec("mitab1");
    spec.setContent(R.id.tab1);
    spec.setIndicator("sss",
            res.getDrawable(android.R.drawable.ic_btn_speak_now));
    tabs.addTab(spec);

    spec=tabs.newTabSpec("mitab2");
    spec.setContent(R.id.tab2);
    spec.setIndicator("TAB2",
            res.getDrawable(android.R.drawable.ic_dialog_map));
    tabs.addTab(spec);



    tabs.setCurrentTab(0);
}

as you can see is very simple. But when I write spec.setIndicator("", res.getDrawable(android.R.drawable.ic_dialog_map)); I can see the icon, bu when I write spec.setIndicator("TAB2", res.getDrawable(android.R.drawable.ic_dialog_map)); I can only see TAB2, but no both of them.

It seems that there are no enougth space to show both. So I've tried to get increase the tab height with this

tabs.getTabWidget().getChildAt(1).getLayoutParams().height = 150; 

but not seems to work.

Dated answered 9/6, 2012 at 17:53 Comment(0)
S
4

//your are over loading the 1st one so you can see only the last added one

 TabHost.TabSpec spec=tabs.newTabSpec("mitab1");

        spec.setIndicator("sss",
                res.getDrawable(android.R.drawable.ic_btn_speak_now));
 Intent sssIntent = new Intent(this, First.class);
 spec.setContent(sssIntent);
        tabs.addTab(spec);

TabHost.TabSpec spec2=tabs.newTabSpec("mitab2");
        spec2=tabs.newTabSpec("mitab2");
        spec2.setIndicator("TAB2",
                res.getDrawable(android.R.drawable.ic_dialog_map));
Intent sssIntent2 = new Intent(this, Second.class);
 spec2.setContent(sssIntent2 );
        tabs.addTab(spec2);
Subminiaturize answered 9/6, 2012 at 20:37 Comment(1)
could you explain a bit more? I dont understand when You say overloading ? thanks a lotDated
B
8

I replaced the label name with null value. Now I can see the icon alone.. Could not find out any other solution.

TabHost.TabSpec spec=tabs.newTabSpec("mitab1");

spec.setIndicator("",
                  res.getDrawable(android.R.drawable.ic_btn_speak_now));
Intent sssIntent = new Intent(this, First.class);
spec.setContent(sssIntent);
tabs.addTab(spec);
Bosley answered 29/6, 2012 at 10:48 Comment(2)
U r right.. we have to clear label of tab to see the icon..thats shit ... By the way Thanks for ur help buddyIconostasis
if place null i'm able to see ..but not able to see the icon text below...can tell i want both icon and text to display...Elevenses
S
4

//your are over loading the 1st one so you can see only the last added one

 TabHost.TabSpec spec=tabs.newTabSpec("mitab1");

        spec.setIndicator("sss",
                res.getDrawable(android.R.drawable.ic_btn_speak_now));
 Intent sssIntent = new Intent(this, First.class);
 spec.setContent(sssIntent);
        tabs.addTab(spec);

TabHost.TabSpec spec2=tabs.newTabSpec("mitab2");
        spec2=tabs.newTabSpec("mitab2");
        spec2.setIndicator("TAB2",
                res.getDrawable(android.R.drawable.ic_dialog_map));
Intent sssIntent2 = new Intent(this, Second.class);
 spec2.setContent(sssIntent2 );
        tabs.addTab(spec2);
Subminiaturize answered 9/6, 2012 at 20:37 Comment(1)
could you explain a bit more? I dont understand when You say overloading ? thanks a lotDated
W
2

The visibility of the icon (together with the label) in the tab depend on the target device and the android platform version.

I had a deeper look into this issue and added more details and a solution at your other (quite similiar) question about this problem; It can be found here:

https://mcmap.net/q/609966/-icon-in-tab-is-not-showing-up

Washburn answered 8/7, 2012 at 0:21 Comment(0)
A
1

Adding this in AndroidManifest.xml solved the issue.

<application 
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
</application>
Arber answered 8/7, 2014 at 18:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.