在ActionBar和Tabs之间放置linearLayout - Android

时间:2014-09-01 14:48:52

标签: android tabs android-actionbar

我试图放置包含ActionBar和The Tabs之间按钮的Linearlayout,我尝试实现一个自定义操作栏,其中包含ActionBar和按钮的水平Linearlayout,但我仍然无法看到按钮,有没有办法这样做?

这是我的自定义actionBar:custom_action_bar_with_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="fill_parent"
         android:layout_height="130dp"
         android:orientation="vertical"
         android:background="@color/blue_buzzvibe">
    <LinearLayout
         android:layout_width="fill_parent"
         android:layout_height="60dp"
         android:background="@color/blue_buzzvibe"
         android:orientation="horizontal"
         >

         <ImageButton android:src="@drawable/icon_menu_white"
             android:id="@+id/cab_main_messages_menu"
             android:background="@drawable/top_header_butt"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:layout_weight="0.2"/>

         <TextView 
             android:id="@+id/cab_main_messages_campaign_name"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:scaleType="centerInside"
             android:text="Campaign Of the day"
             android:textColor="@color/white"
             android:textSize="18dp"
             android:gravity="center"
             android:layout_weight="1" 
             /> 
         <ImageButton android:src="@drawable/ic_plus_wh"
             android:id="@+id/cab_main_messages_propose_message"
             android:background="@drawable/top_header_butt"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:layout_weight="0.2" />
</LinearLayout>
<LinearLayout
    android:id="@+id/options_buttons_campaign"
    android:layout_width="fill_parent"
    android:layout_height="70dp"
    android:gravity="center_vertical|center_horizontal" >
        <ImageButton
            android:id="@+id/home_desc_butt"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/icon_mail_alt"
            android:background="@drawable/layout_header_selector"
            />
        <View
            android:layout_width="2dip"
            android:layout_height="fill_parent"
            android:background="@color/light_gray"
            />
        <ImageButton
            android:id="@+id/msg_list_butt_details"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/icon_mail_alt"
            android:background="@drawable/layout_header_selector"
            />
        <View
            android:layout_width="2dip"
            android:layout_height="fill_parent"
            android:background="@color/light_gray"
            />
        <ImageButton
            android:id="@+id/campaign_metrics"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/ic_metrics"
            android:background="@drawable/layout_header_selector"
            android:clickable="true"
            />
        <View
            android:layout_width="2dip"
            android:layout_height="fill_parent"
            android:background="@color/light_gray"
        />
        <ImageButton
            android:id="@+id/people_list_butt"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/social_myspace"
            android:background="@drawable/layout_header_selector"
            android:clickable="true"
            />
    </LinearLayout>

</LinearLayout>

在onCreate中,我调用此方法来初始化我的操作栏:

public void initActionBar(){
    mActionBar = getSupportActionBar();
    View customView =  
    getLayoutInflater().inflate(R.layout.custom_action_bar_with_menu,null);
    mActionBar.setCustomView(customView, new  
    ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, 
    ActionBar.LayoutParams.WRAP_CONTENT));//(int) (90*scale + 0.5f))); 
    mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    mActionBar.setDisplayShowHomeEnabled(true);

     /** Set tab navigation mode */
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}

我不想动态更改动作栏高度,以显示我的所有自定义动作栏

1 个答案:

答案 0 :(得分:0)

您可以在ActionBar(包含按钮)中创建自定义视图,并在活动的ActionBar方法中将此自定义视图设置为OnCreate()

示例:

public class YourActivity extends ActionBarActivity {

    private ActionBar actionBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        actionBar= getActionBar();
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            actionBar.setCustomView(R.layout.custom_view);
    }
}

How to create custom view for ActionBar question