自定义ActionBar

1 /**
2      * 自定义ActionBar
3      */
4     private void CustomeActionBar() {
5         ActionBar actionBar = getSupportActionBar();
6         actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
7         actionBar.setDisplayShowCustomEnabled(true);
8         actionBar.setCustomView(R.layout.header_layout);
9     }
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="55dp"
 5     android:background="@drawable/background_slice_normal" >
 6 
 7     <Button
 8         android:id="@+id/Button_Left"
 9         android:layout_width="wrap_content"
10         android:layout_height="match_parent"
11         android:layout_alignParentLeft="true"
12         android:background="@drawable/button_background"
13         android:gravity="center"
14         android:paddingLeft="10dp"
15         android:paddingRight="10dp"
16         android:text="@string/pageleft"
17         android:textColor="#FFF"
18         android:textSize="15sp" />
19 
20     <TextView
21         android:id="@+id/TextView_PageName"
22         android:layout_width="wrap_content"
23         android:layout_height="match_parent"
24         android:layout_centerInParent="true"
25         android:gravity="center"
26         android:text="@string/pagename"
27         android:textColor="#FFF"
28         android:textSize="18sp" />
29 
30     <Button
31         android:id="@+id/Button_Right"
32         android:layout_width="wrap_content"
33         android:layout_height="match_parent"
34         android:layout_alignParentRight="true"
35         android:background="@drawable/button_background"
36         android:gravity="center"
37         android:paddingLeft="10dp"
38         android:paddingRight="10dp"
39         android:text="@string/pageright"
40         android:textColor="#FFF"
41         android:textSize="15sp" />
42 
43 </RelativeLayout>
原文地址:https://www.cnblogs.com/lavalike/p/4708890.html