private void initActionBar() {
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
View view = UIUtils.inflate(R.layout.layout_discover_actionbar);
Button iv = (Button) view.findViewById(R.id.iv_dis_actionbar_back);
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
actionBar.setCustomView(view);//自定义ActionBar布局
}
布局代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:gravity="center_vertical"
android:orientation="horizontal">
<Button
android:id="@+id/iv_dis_actionbar_back"
android:layout_width="32dp"
android:background="@drawable/ic_brows_back"
android:layout_height="32dp"
android:gravity="center_vertical"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="好友圈"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>