【发布时间】:2013-12-27 01:38:52
【问题描述】:
尝试为我的操作栏设置自定义视图,但问题是它没有填满操作栏的整个宽度,这让我很难将对象居中。如何在我的操作栏中设置一个自定义视图来填满整个操作栏?
设置我的操作栏的代码:
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>
【问题讨论】:
标签: android android-custom-view android-actionbar-compat