我正在尝试将标签样式设置为浅色主题.给我白色标签.我尝试了几种方法,但我无法让这些人改变颜色!我可以在Manifest,TabHost或Tab Widget中分配主题吗?
style.xml
<style name="SBstyle" parent="@androID:style/theme.light"> <item name="androID:windowNoTitle">true</item> <item name="androID:tabWidgetStyle">@style/lightTabWidget</item></style><style name="lightTabWidget" parent="@androID:style/Widget.TabWidget"><item name="androID:textcolor">#de6001</item>
然后我有
我的Manifest.xml
<application androID:icon="@drawable/icon" androID:label="@string/app_name" androID:theme="@style/SBstyle">
最后是我的tab.xml
<?xml version="1.0" enCoding="utf-8"?> <TabHost xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:ID="@androID:ID/tabhost"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent"androID:background="#ffffff"><linearLayout androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:padding="0dp" > <include layout="@layout/nav_bar" androID:layout_height="47dp" androID:layout_wIDth="fill_parent" androID:layout_alignParenttop="true" /> <TabWidget androID:ID="@androID:ID/tabs" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:background="#f8a96e" androID:tabStripEnabled="false" /> <FrameLayout androID:ID="@androID:ID/tabcontent" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:padding="5dp" /></linearLayout></TabHost>
感谢您的帮助,谢谢!
解决方法:
如果您使用完全自定义选项卡,则可以对选项卡执行任何 *** 作.这是代码..希望它有帮助:
private voID initializeTabs(int curTab) { this.tabHost = getTabHost(); tabHost.clearallTabs(); TabSpec ts1, ts2, ts3, ts4, ts5; // tab separator tabHost.getTabWidget().setdivIDerDrawable(R.drawable.tab_divIDer); ts1 = this.setupTab(new TextVIEw(this), tabHost, R.drawable.browse_tab_normal, mResources.getString(R.string.browse)); ts2 = this.setupTab(new TextVIEw(this), tabHost, R.drawable.search_tab_normal, mResources.getString(R.string.Search)); ts3 = this.setupTab(new TextVIEw(this), tabHost, R.drawable.postad_tab_normal, mResources.getString(R.string.Post)); ts4 = this.setupTab(new TextVIEw(this), tabHost, R.drawable.watchList_tab_normal, mResources.getString(R.string.WatchList)); ts5 = this.setupTab(new TextVIEw(this), tabHost, R.drawable.managead_tab_normal, mResources.getString(R.string.Login)); // intents ts1.setContent(new Intent().setClass(this, browsetabactivity.class)); ts2.setContent(new Intent().setClass(this, Searchtabactivity.class)); ts3.setContent(new Intent().setClass(this, PostAdtabactivity.class)); ts4.setContent(new Intent().setClass(this, WatchListtabactivity.class)); ts5.setContent(new Intent().setClass(this, Logintabactivity.class)); tabHost.addTab(ts1); tabHost.addTab(ts2); tabHost.addTab(ts3); tabHost.addTab(ts4); tabHost.addTab(ts5); /** * reset the tabs by showing the tab home screen everytime the tab * is clicked in any screen other than home screen. */ getTabWidget().getChildAt(0).setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (getTabHost().getCurrentTabTag().equals(mTag1) == false) { getTabHost().setCurrentTab(0); } handleTabClicks(); } }); getTabWidget().getChildAt(2).setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (getTabHost().getCurrentTabTag().equals(mTag2) == false) { getTabHost().setCurrentTab(1); } handleTabClicks(); } }); getTabWidget().getChildAt(4).setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (getTabHost().getCurrentTabTag().equals(mTag3) == false) { getTabHost().setCurrentTab(2); } handleTabClicks(); } }); getTabWidget().getChildAt(6).setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (getTabHost().getCurrentTabTag().equals(mTag4) == false) { getTabHost().setCurrentTab(3); } handleTabClicks(); } }); // Login getTabWidget().getChildAt(8).setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (getTabHost().getCurrentTabTag().equals(mTag5) == false) { getTabHost().setCurrentTab(4); } handleTabClicks(); } }); // so that we can programatically switch tabs ((ApplicationHelper) getApplication()).setTabHost(tabHost); fl = (FrameLayout) findVIEwByID(androID.R.ID.tabcontent); tabHost.setCurrentTab(curTab);}
我从onCreate()调用initializeTabs().
setupTab看起来像这样:
private TabSpec setupTab(final VIEw vIEw, final TabHost mTabHost, final int imageID, final String tag) { final VIEw tabvIEw = createTabVIEw(mTabHost.getContext(), imageID, tag); TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabvIEw).setContent(new TabContentFactory() { public VIEw createTabContent(String tag) {return vIEw;} }); return setContent;}private static VIEw createTabVIEw(final Context context, final int imageID, final String text) { VIEw vIEw = LayoutInflater.from(context).inflate(R.layout.tab_with_icon, null); TextVIEw tv = (TextVIEw) vIEw.findVIEwByID(R.ID.tabTitle); tv.setText(text); ImageVIEw iv = (ImageVIEw) vIEw.findVIEwByID(R.ID.iconImage); if (iv != null) iv.setimageResource(imageID); vIEw.setTag(text); vIEw.setBackgroundResource(R.drawable.tab_bg_selector); // only refresh on watchList if (text.equals(context.getString(R.string.WatchList))) refreshTab(context, vIEw); else { relativeLayout countLayout = (relativeLayout) vIEw.findVIEwByID(R.ID.countLayout); if (countLayout != null) countLayout.setVisibility(VIEw.GONE); } return vIEw;}
最后,R.layout.tab_with_icon的XML:
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/tabsLayout" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:background="@drawable/tab_bg_selector" androID:orIEntation="vertical"> <relativeLayout androID:layout_wIDth="wrap_content" androID:ID="@+ID/relativeLayout1" androID:layout_height="wrap_content" androID:gravity="center" androID:layout_centerInParent="true" androID:background="@drawable/tab_bg_selector"> <ImageVIEw androID:layout_wIDth="wrap_content" androID:ID="@+ID/iconImage" androID:src="@drawable/watchList_tab_normal" androID:layout_height="wrap_content" androID:layout_centerHorizontal="true"></ImageVIEw> <TextVIEw androID:text="Title" androID:layout_wIDth="wrap_content" androID:ID="@+ID/tabTitle" androID:layout_height="wrap_content" androID:layout_below="@+ID/iconImage" androID:layout_centerHorizontal="true" androID:ellipsize="marquee" androID:lines="1" androID:maxlines="1" androID:scrollHorizontally="true" androID:textSize="@dimen/tabTextSize"></TextVIEw> <relativeLayout androID:layout_wIDth="wrap_content" androID:ID="@+ID/countLayout" androID:layout_height="wrap_content" androID:layout_alignRight="@+ID/iconImage"> <ImageVIEw androID:layout_wIDth="wrap_content" androID:ID="@+ID/redImage" androID:src="@drawable/watchList_count" androID:layout_height="wrap_content"></ImageVIEw> <TextVIEw androID:text="1" androID:textcolor="@color/white" androID:layout_wIDth="wrap_content" androID:ID="@+ID/countText" androID:layout_height="wrap_content" androID:layout_centerInParent="true" androID:textStyle="bold"></TextVIEw> </relativeLayout> </relativeLayout></relativeLayout>
总结 以上是内存溢出为你收集整理的android – 如何将Tab样式设置为浅色主题w彩色文本?全部内容,希望文章能够帮你解决android – 如何将Tab样式设置为浅色主题w彩色文本?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)