Android ActionBar.Tab setCustomView()没有fill_parent

Asa*_*evo 9 tabs android android-actionbar

我在这个布局中使用ActionBar.Tab setCustomView()方法:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_grey" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="Test Tab" 
        android:textColor="@color/background_dark_green"/>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是我设置ActionBar的函数:

public void setActionBar()
{
    ActionBar actionBar = getSupportActionBar();
    //actionBar.hide();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);        
    //set action bar navigation mode
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        
    //set tabs      
    //home tab 
    Tab tab = actionBar.newTab().setText(TAB_HOME).setTabListener(new PicoTabListener<StartFragment>(this, StartFragment.class));       
    tab.setCustomView(R.layout.tab_background);
    actionBar.addTab(tab);
    //events tab
    tab = actionBar.newTab().setText(TAB_EVENTS).setTabListener(new PicoTabListener<EventsFragment>(this, EventsFragment.class));
    actionBar.addTab(tab);      
    //enter event code
    tab = actionBar.newTab().setText(TAB_CODE).setTabListener(new PicoTabListener<EnterCodeFragment>(this, EnterCodeFragment.class));
    actionBar.addTab(tab);      
}
Run Code Online (Sandbox Code Playgroud)

和我的活动布局:

<?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/background_dark_green" >

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

结果看起来像这样(左上角的选项卡带有灰色背景): 在此输入图像描述

如何使我的自定义视图填充整个选项卡并正常工作?

我正在使用Android 2.3支持包v7

CQM*_*CQM 0

在处理actionbarcompat的setCustomView时你必须依赖android:marginandroid:padding

请记住,根元素的填充、宽度、高度和边距似乎被忽略了。