android中使用setCustomView不能填满actionbar的问题

在安卓原生日历中日程的编辑界面的title是用setCustomView来自定义的。自定义actionbar的代码基本是如下形式:

ViewGroup customView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.pen_note_custom_title, null);
getActionBar().setCustomView(customView);

一直以来我都是这样做的,但是当我尝试达到如下效果的时候,却怎么也做不到。

取消和完成分别是两个LinearLayout做成的,从上图可以看出,这两个LinearLayout是平分了actionbar的。平分actionbar是通过如下代码来设置LinearLayout的style:

<style name="EditEventCustomActionButton" parent="android:style/Widget.Holo.Light.ActionButton">
    <item name="android:layout_height">match_parent</item>
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_weight">1</item>
    <item name="android:focusable">true</item>
    <item name="android:orientation">horizontal</item>
</style>

但是按照刚刚给出的代码怎么也做不出日历效果来,通过给我自定义的布局填充一个背景发现我的自定义布局根本没有填满actionbar。

原来问题出这里:

ViewGroup customView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.pen_note_custom_title, null);

日历中使用了不同的参数,有三个参数:

View actionBarButtons = inflater.inflate(R.layout.edit_event_custom_actionbar,
                    new LinearLayout(mContext), false);

其中第二个参数new``LinearLayout(mContext)决定了该如何显示自定义的view。于是我改写了inflate的方式,问题解决了。