4

我添加标签来我这个代码的应用程序:Android的标签定制查看

ActionBar.Tab tab1=actionBar.newTab(); 
tab1.setTabListener(this); 
tab1.setCustomView(R.layout.tab_style); 
TextView txt1 = (TextView)tab1.getCustomView().findViewById(R.id.tabtext); 
txt1.setText(R.string.tab_1); 
actionBar.addTab(tab1); 

这是tab_style.xml

<?xml version="1.0" encoding="utf-8"?> 
<!-- This is the main layout of the application --> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/fragment_basic_root" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/white" 
    android:paddingBottom="15dp" 
    > 


<TextView 
    android:id="@+id/tabtext" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:gravity="center_vertical" 
    android:paddingLeft="6dip" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:textSize="20dp" 
/> 
</RelativeLayout> 

我想改变标签的背景,但结果是:

enter image description here

我怎样才能解决这个问题? Customview不居中。

+0

将'android:paddingBottom =“0dip”'添加到relativelayout中 – mmlooloo 2014-09-27 15:36:22

+0

不起作用。同样的 – 2014-09-27 17:18:25

回答

2

动作栏选项卡中的“L”开发者预览版弃用。

黑色区域是背景actionBar tabBar。您必须设置actionBarTabBarStyle的样式并设置它的背景。看看这个链接:

http://blog.alwold.com/2013/08/28/styling-tabs-in-the-android-action-bar/

,或者您可以使用其他的库,如:

PagerSlidingTabStrip

,或者如果你想有一个谷歌的一个,你可以尝试:

SlidingTabsBasic

+0

你的意思是我必须改变我的标签系统? – 2014-10-01 15:05:22

+0

我认为你最好这样做! – mmlooloo 2014-10-01 15:17:33

+0

PagerSlidingTabStrip是不错的? – 2014-10-01 15:24:11

0

尝试利润率按在你的TextView您的要求,这将有助于

+0

我试过但没有工作 – 2014-09-27 12:27:04

+0

试试这个链接它会帮助http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/ – 2014-09-27 12:30:59

+0

我已经在使用这段代码了。紧接着本教程。但没有关于选项卡背景颜色的信息。 – 2014-09-27 12:37:05