尝试为我的操作栏设置自定义视图,但问题是它没有填满操作栏的整个宽度,这使得我可以使对象居中.如何在我的操作栏中设置自定义视图以填满整个操作栏?
设置我的操作栏的代码:
actionBar.setdisplayShowHomeEnabled(false); actionBar.setdisplayShowCustomEnabled(true); actionBar.setdisplayShowTitleEnabled(false); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); actionBar.setCustomView(inflater.inflate(R.layout.actionbar_layout,null));
还有我的actionbar_layout.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#EDEDED"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/title" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:textColor="#FFFFFF" android:text="Testing"/> </RelativeLayout>