2011-06-01 20 views
12

मैं अपने आवेदन में टैब दिखाने के लिए चाहते हैं के बीच है, लेकिन टैब्स के बीच एंड्रॉयड में डिफ़ॉल्ट रूप से विभक्त लाइन को हटाने के इसबदलें टैब पृष्ठभूमि रंग और टैब

      Tab1 | Tab2 | Tab3 | 

तरह विभक्त लाइन है, लेकिन मैं इस

तरह टैब दिखाने के लिए चाहते हैं
      Tab1 Tab2 Tab3 

तो मैं दो टैब के बीच विभाजक रेखा को हटाना चाहता हूं और डिफ़ॉल्ट रूप से टैब पृष्ठभूमि रंग ग्रे रंग है। इसलिए मैं इसे काला रंग में बदलना चाहता हूं।

कृपया बताएं कि दो टैब के बीच विभाजक रेखा को कैसे निकालें और टैब के पृष्ठभूमि रंग को बदलें।

अग्रिम धन्यवाद।

सर्वश्रेष्ठ सादर।

उत्तर

10

टैब के लिए अपने स्वयं के लेआउट का उपयोग करने के लिए इस विधि और लेआउट का उपयोग करें। विभाजक को हटाने के लिए बस पृष्ठभूमि 9 पैच ग्राफ़िक को अपने आप से बदलें।

public static View prepareTabView(Context context, String text, Drawable background) { 
    View view = LayoutInflater.from(context).inflate(R.layout.fake_native_tab, null); 
    TextView tv = (TextView) view.findViewById(R.id.fakeNativeTabTextView); 
    tv.setText(text); 
    view.setBackgroundDrawable(background); 
    return view; 
} 

fake_native_tab.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/fakeNativeTabLayout" android:layout_width="wrap_content" 
android:layout_height="wrap_content" android:gravity="center" 
android:orientation="vertical" android:background="@drawable/default_tab_background"> 
<!-- 
     You can even define an Icon here (dont forget to set a custom icon in your code for each Tab): 
    <ImageView android:id="@+id/fakeNativeTabImageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:src="@drawable/icon" /> 
--> 
    <TextView android:id="@+id/fakeNativeTabTextView" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:textColor="@color/tab_text_color" android:textSize="@dimen/text_size_tiny" 
    android:text="Tab" android:ellipsize="marquee" /> 

</LinearLayout> 

उपयोग (अपने TabActivity अंदर):

/* Create Tabs */ 
// reusable Tab Spec 
TabHost.TabSpec spec; 
Intent tabIntent; 
tabHost = getTabHost(); 
Resources res = getResources(); 

// Tab 1: 
tabIntent = new Intent().setClass(this, Favorite.class); 
    spec = tabHost.newTabSpec(TAB_SOMETAB).setIndicator(
      prepareTabView(this, (String) getText(R.string.tab_favorite), res 
        .getDrawable(R.drawable.tab_favorite_background), 0)).setContent(tabIntent); 
tabHost.addTab(spec); 



// Tab 2: 
tabIntent = new Intent().setClass(this, History.class); 
spec = tabHost.newTabSpec(TAB_SOMEOTHERTAB).setIndicator(
      prepareTabView(this, (String) getText(R.string.tab_history), res 
        .getDrawable(R.drawable.tab_favorite_background), 0)).setContent(tabIntent); 
tabHost.addTab(spec); 
+0

धन्यवाद था और मैं भी दो टैब्स के बीच में विभक्त लाइन निकालना चाहते हैं। कृपया मुझे बताएं कि दो टैब – Ramakrishna

+0

के बीच विभाजक रेखा को कैसे निकालना संभव है, टैब की चौड़ाई और ऊंचाई को प्रोग्रामेटिक रूप से सेट करना संभव है, इसलिए चौड़ाई का विस्तार करने का प्रयास करें, तो आप इसे प्राप्त कर सकते हैं ... – Lavanya

+0

बस एक पृष्ठभूमि ग्राफ़िक का उपयोग करें जिसमें विभाजक नहीं है इसमें लाइन – Mannaz

61

उपयोग:

tabHost.getTabWidget().setDividerDrawable(null); 

विभक्त लाइनों को हटाने के लिए।

+0

लाइनों को हटा दिया जाता है लेकिन टैब के बीच अंतर के बारे में क्या ?? – MobileEvangelist

+0

धन्यवाद एक टन :) – Nevaeh

24

मुझे आईसीएस में समस्या थी, जहां विभाजक दिखाई दे रहा था। निम्न में से कोई भी समाधान काम करने के अलावा काम नहीं करता है।

<TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="60dp" 
      android:gravity="bottom" 
      android:layout_alignParentBottom="true" 
      android:fadingEdge="none" 
      android:showDividers="none" > 
     </TabWidget> 

कुंजी लाइन जबाब देने के लिए android:showDividers="none"

+0

यह सही जवाब है वैसे भी ... – erikaD

संबंधित मुद्दे