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