0

탭 컬러 스트립을 제거하고 싶습니다. setStripEnabled(false);을 시도했지만 작동하지 않았습니다. 또한 android:tabStripEnabled="false"을 XML 코드로 시도했습니다. 탭 표시 줄은 여전히 ​​탭 표시 줄에 나타납니다. 누군가가 탭 바에서 발생하는 파란색 스트립을 어떻게 제거 할 수 있는지 말해 줄 수 있습니까?android에서 tabStrip을 제거하는 방법은 무엇입니까?

JAVA CODE: 

public class TabsFragmentActivity extends FragmentActivity implements TabHost.OnTabChangeListener { 
private TabHost mTabHost; 
private HashMap mapTabInfo = new HashMap(); 
private TabInfo mLastTab = null; 

private class TabInfo { 
    private String tag; 
    private Class clss; 
    private Bundle args; 
    private Fragment fragment; 
    TabInfo(String tag, Class clazz, Bundle args) { 
     this.tag = tag; 
     this.clss = clazz; 
     this.args = args; 
    } 

} 

class TabFactory implements TabContentFactory { 

    private final Context mContext; 

    /** 
    * @param context 
    */ 
    public TabFactory(Context context) { 
     mContext = context; 
    } 

    /** (non-Javadoc) 
    * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String) 
    */ 
    public View createTabContent(String tag) { 
     View v = new View(mContext); 
     v.setMinimumWidth(0); 
     v.setMinimumHeight(0); 
     return v; 
    } 

} 
/** (non-Javadoc) 
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle) 
*/ 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    // Step 1: Inflate layout 
    setContentView(R.layout.tabs_layout); 
    // Step 2: Setup TabHost 
    initialiseTabHost(savedInstanceState); 
    if (savedInstanceState != null) { 
     mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state 

    } 
} 

/** (non-Javadoc) 
* @see android.support.v4.app.FragmentActivity#onSaveInstanceState(android.os.Bundle) 
*/ 
protected void onSaveInstanceState(Bundle outState) { 
    outState.putString("tab", mTabHost.getCurrentTabTag()); //save the tab selected 
    super.onSaveInstanceState(outState); 
} 

/** 
* Step 2: Setup TabHost 
*/ 
private void initialiseTabHost(Bundle args) { 
    mTabHost = (TabHost)findViewById(android.R.id.tabhost); 
    mTabHost.setup(); 

    TabInfo tabInfo = null; 
    Resources res = getResources(); 
    this.mTabHost.getTabWidget().setStripEnabled(false); 
    TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("",res.getDrawable(R.drawable.ic_launcher)), (tabInfo = new TabInfo("Tab1", Tab1Fragment.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 
    TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("",res.getDrawable(R.drawable.ic_launcher)), (tabInfo = new TabInfo("Tab2", Tab2Fragment.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 
    TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("",res.getDrawable(R.drawable.ic_launcher)), (tabInfo = new TabInfo("Tab3", Tab3Fragment.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 

    // Default to first tab 
    this.onTabChanged("Tab1"); 
    // 
    mTabHost.setOnTabChangedListener(this); 
} 

/** 
* @param activity 
* @param tabHost 
* @param tabSpec 
* @param clss 
* @param args 
*/ 
private static void addTab(TabsFragmentActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) { 
    // Attach a Tab view factory to the spec 
    tabSpec.setContent(activity.new TabFactory(activity)); 
    String tag = tabSpec.getTag(); 

    // Check to see if we already have a fragment for this tab, probably 
    // from a previously saved state. If so, deactivate it, because our 
    // initial state is that a tab isn't shown. 
    tabInfo.fragment = activity.getSupportFragmentManager().findFragmentByTag(tag); 
    if (tabInfo.fragment != null && !tabInfo.fragment.isDetached()) { 
     FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction(); 
     ft.detach(tabInfo.fragment); 
     ft.commit(); 
     activity.getSupportFragmentManager().executePendingTransactions(); 
    } 

    tabHost.addTab(tabSpec); 
} 

/** (non-Javadoc) 
* @see android.widget.TabHost.OnTabChangeListener#onTabChanged(java.lang.String) 
*/ 
public void onTabChanged(String tag) { 
    TabInfo newTab = (TabInfo) this.mapTabInfo.get(tag); 
    if (mLastTab != newTab) { 
     FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction(); 
     if (mLastTab != null) { 
      if (mLastTab.fragment != null) { 
       ft.detach(mLastTab.fragment); 
      } 
     } 
     if (newTab != null) { 
      if (newTab.fragment == null) { 
       newTab.fragment = Fragment.instantiate(this, 
         newTab.clss.getName(), newTab.args); 
       ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag); 
      } else { 
       ft.attach(newTab.fragment); 
      } 
     } 

     mLastTab = newTab; 
     ft.commit(); 
     this.getSupportFragmentManager().executePendingTransactions(); 
    } 
} 

XML 코드 -

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


     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:layout_weight="0"/> 

     <FrameLayout 
      android:id="@+android:id/realtabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"/> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      android:background="@drawable/tabbar_bg" 
      android:tabStripEnabled="false"/> 


    </LinearLayout> 
</TabHost> 
</LinearLayout> 
+1

참조 링크 : http://stackoverflow.com/questions/12342818/how-to-change-color-of- the-tabstrip-in-android & http://stackoverflow.com/questions/14722654/tabwidget-current-tab-bottom-line-color – VVB

+1

다음을 확인하십시오 : http://stackoverflow.com/questions/20538607/fragmenttabhost- tabwidget-tabstrip-can not-customized 사용자 정의 –

+0

해결책을 찾으십시오. 고마워요 http://stackoverflow.com/questions/20404907/how-to-set-background-color-tabhost – koherent

답변

1

당신의 스타일 XML 파일

<style name="AppTheme" parent="AppBaseTheme"> 
    <item name="android:tabWidgetStyle">@style/LightTabWidget</item> 
</style> 

<style name="LightTabWidget" parent="@android:style/Widget.TabWidget"> 
    <item name="android:tabStripEnabled">false</item> 
</style> 
0

간단하게 설정 자식 배경으로 null로이 줄을 추가하면 완료했다. 자세한 내용 들어 내 대답 확인

fragmentTabHost.getTabWidget().getChildAt("Your tab position").setBackground(null); 

내 대답 시도 Link

관련 문제