2012-06-09 9 views
8

Próbuję zrobić prostą aplikację z kartami w Androidzie za pomocą dwóch kart. Mój problem polega na tym, że kiedy umieszczam ten kod, na karcie wyświetla się tylko tekst, ale nie ikony. Jeśli umieściłem tekst na "" ikona jest wyświetlana.Ikona karty nie pokazuje się

Czy ktoś mógłby mi pomóc? Moja wersja na Androida to 4.0.3.

Wielkie dzięki.

<?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> 

i oznaczeniem aktywności jest

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); 
} 

jak widać jest bardzo prosta. Ale kiedy piszę spec.setIndicator("", res.getDrawable(android.R.drawable.ic_dialog_map)); widzę ikonę, bu gdy piszę spec.setIndicator("TAB2", res.getDrawable(android.R.drawable.ic_dialog_map)); Widzę tylko TAB2, ale nie ma ich obu.

Wygląda na to, że nie ma miejsca na enougth, aby pokazać oba. Próbowałem więc zwiększyć wysokość zakładki tym, ale wydaje się, że nie działa.

Odpowiedz

4

// Twój minęły ładowania 1st jeden, więc można zobaczyć tylko ostatni dodaje jeden

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); 
+0

Czy możesz wyjaśnić nieco więcej? Nie rozumiem, kiedy mówisz przeciążenie? bardzo dziękuję – theholy

+0

To nie działa dla mnie –

8

Wymieniłem nazwę etykiety o wartości zerowej. Teraz widzę samą ikonę .. Nie można znaleźć żadnego innego rozwiązania.

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); 
+0

U r prawo .. musimy wyczyścić etykietę tabulatora, aby zobaczyć ikonę..to gówno ... Przy okazji Dzięki za ur pomoc kumpla – Noman

+0

czy miejsce null jestem mogę zobaczyć ... ale nie widzę tekstu ikony poniżej ... mogę powiedzieć, że chcę wyświetlać zarówno ikonę, jak i tekst ... –

2

Widoczność ikony (wraz z etykietą) w zakładce zależy od urządzenia docelowego i wersji platformy Android.

Miałem głębsze spojrzenie na ten problem i dodałem więcej szczegółów i rozwiązania na inne (podobne) pytanie o ten problem; Można go znaleźć tutaj:

https://stackoverflow.com/a/11379708/414581

0

Dodanie tego w AndroidManifest.xml rozwiązać ten problem.

<application 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@android:style/Theme.NoTitleBar"> 
</application>