2012-06-09 18 views
8

नहीं दिखा रहा आइकन मैं दो टैब के साथ एंड्रॉयड में एक साधारण टैब एप्लिकेशन करने के लिए कोशिश कर रहा हूँ। मेरी समस्या यह है कि जब मैं यह कोड डालता हूं, टैब में, केवल पाठ दिखाया जाता है, लेकिन कोई आइकन नहीं। यदि मैंने टेक्स्ट को "" आइकन में दिखाया है तो दिखाया गया है।टैब

कोई मेरी मदद कर सकते हैं? मेरा एंड्रॉइड संस्करण 4.0.3 है।

बहुत बहुत धन्यवाद।

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

और गतिविधि कोड

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

के रूप में आप देख सकते हैं बहुत ही सरल है। लेकिन जब मैं spec.setIndicator("", res.getDrawable(android.R.drawable.ic_dialog_map)); बारे में मैं आइकन देख सकते हैं, बू जब मैं spec.setIndicator("TAB2", res.getDrawable(android.R.drawable.ic_dialog_map)); बारे में मैं केवल tab2 देख सकते हैं, लेकिन उनमें से कोई दोनों।

ऐसा लगता है दोनों दिखाने के लिए कोई enougth अंतरिक्ष देखते हैं कि। तो मैं इस

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

साथ टैब ऊंचाई बढ़ाने के प्राप्त करने की कोशिश की है, लेकिन काम करने के लिए लगता है नहीं।

उत्तर

4

// 1 एक तो आप देख सकते हैं लोड हो रहा है पर अपने ही पिछले एक

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

क्या आप थोड़ा और समझा सकते हैं? जब आप ओवरलोडिंग कहते हैं तो मैं समझ नहीं पा रहा हूं? बहुत बहुत धन्यवाद – theholy

+0

यह मेरे लिए काम नहीं करता –

8

जोड़ा मैं शून्य मान के साथ लेबल नाम बदल दिया। अब मैं आइकन अकेला देख सकते हैं .. नाबाद किसी अन्य समाधान ढूंढा जा सका।

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

यू आर दाएं .. हमें आइकन देखने के लिए टैब के लेबल को साफ़ करना होगा .. वैसे आपकी मदद के लिए धन्यवाद दोस्त – Noman

+0

यदि जगह शून्य है देखने में सक्षम .. लेकिन नीचे दिए गए आइकन टेक्स्ट को देखने में सक्षम नहीं है ... बता सकता हूं कि मैं आइकन और टेक्स्ट दोनों को प्रदर्शित करना चाहता हूं ... –

2

टैब में आइकन (एक साथ लेबल के साथ) की दृश्यता लक्ष्य डिवाइस और Android प्लेटफ़ॉर्म वर्ज़न पर निर्भर हैं।

मुझे इस मुद्दे पर गहराई से नजर आया और इस समस्या के बारे में आपके अन्य (काफी समान) प्रश्न पर अधिक जानकारी और समाधान जोड़ा गया; यह यहां पाया जा सकता:

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

0

AndroidManifest.xml में यह जोड़ने से समस्या हल हो जाती।

<application 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@android:style/Theme.NoTitleBar"> 
</application> 
संबंधित मुद्दे