2010-07-02 7 views
8

एंड्रॉइड 2.2 में टैबविड्ज के लिए सक्षम है i.e एपीआई लेवल 8 में TabWidget के लिए tabStripEnabled = "true" है एंड्रॉइड के पुराने संस्करणों में इसे कैसे प्राप्त किया जाए?टैबस्ट्रिप पुराने एपीआई के

+0

मैं था स्क्रीन के नीचे टैब्स, तो मैं इसे नीचे के रूप में किया था ... मैं एंड्रॉयड डाल: "- 10dip" layout_marginBottom = bottomStrip स्क्रीन बंद चलती लेकिन यह करने के लिए सही रास्ता पता करना चाहते हैं ... धन्यवाद – amithgc

उत्तर

8
private void SetupTabs(TabHost tabHost) { 

    LinearLayout ll = (LinearLayout) tabHost.getChildAt(0); 
    TabWidget tw = (TabWidget) ll.getChildAt(0); 

    Field mBottomLeftStrip; 
    Field mBottomRightStrip; 

    try { 
     mBottomLeftStrip = tw.getClass().getDeclaredField("mBottomLeftStrip"); 
     mBottomRightStrip = tw.getClass().getDeclaredField("mBottomRightStrip"); 

     if (!mBottomLeftStrip.isAccessible()) { 
      mBottomLeftStrip.setAccessible(true); 
     } 

     if (!mBottomRightStrip.isAccessible()) { 
      mBottomRightStrip.setAccessible(true); 
     } 

     mBottomLeftStrip.set(tw, getResources().getDrawable(R.drawable.blank)); 
     mBottomRightStrip.set(tw, getResources().getDrawable(R.drawable.blank));// blank is the name of the image in drawable folder 

    } 
    catch (java.lang.NoSuchFieldException e) { 
     // possibly 2.2 
     try { 
      Method stripEnabled = tw.getClass().getDeclaredMethod("setStripEnabled", boolean.class); 
      stripEnabled.invoke(tw, false); 

     } 
     catch (Exception e1) { 
      e1.printStackTrace(); 
     } 
    } 
    catch (Exception e) {} 
} 
+0

आपका बहुत बहुत धन्यवाद!!!! – Eby

+0

यह मेरे लिए काम नहीं किया। मैंने इसे 2.1 और 2.2 एमुलेटर दोनों पर करने की कोशिश की। क्या इस और हैक का उपयोग करते समय मुझे कुछ और विचार करना चाहिए? यह वर्तमान एसडीके के आधार पर सही ढंग से निष्पादित कोड है लेकिन TabWidget के लिए नीचे सीमा बनी हुई है। – dannyroa

+1

यह सही काम करता है, कुछ चीजों को ध्यान में रखना, एक पारदर्शी छवि बनाना और इसे खाली नाम देना। मैंने टिप्पणी करके थोड़ा बदलाव किया: रैखिक लयआउट ll = (LinearLayout) tabHost.getChildAt (0); टैबविड्ज TW = (TabWidget) ll.getChildAt (0); और टैबविड्ज tw = tabHost.getTabWidget(); – Fred

0

मैं यह इतना बनाया:

try { 
     Method setStripEnabled = tabWidget.getClass().getDeclaredMethod(
       "setStripEnabled", boolean.class); 
     setStripEnabled.invoke(tabWidget, true); 

     Method setLeftStripDrawable = tabWidget.getClass() 
       .getDeclaredMethod("setLeftStripDrawable", int.class); 
     setLeftStripDrawable.invoke(tabWidget, R.drawable.tab_line); 

     Method setRightStripDrawable = tabWidget.getClass() 
       .getDeclaredMethod("setRightStripDrawable", int.class); 
     setRightStripDrawable.invoke(tabWidget, R.drawable.tab_line); 
    } catch (NoSuchMethodException e) { 
     e.printStackTrace(); 
    } catch (IllegalArgumentException e) { 
     e.printStackTrace(); 
    } catch (IllegalAccessException e) { 
     e.printStackTrace(); 
    } catch (InvocationTargetException e) { 
     e.printStackTrace(); 
    } 
संबंधित मुद्दे