我想要一个带有自定义视图的简单操作栏,但我得到了以下结果:
为了演示,我创建了一个简单的XML文件,具有黄色背景颜色,它应该占据整个宽度。
这是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="match_parent"
android:background="@color/yellow"
android:orientation="vertical" >
<TextView
android:visibility="gone"
android:id="@+id/action_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/action_save"
android:gravity="center"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:textColor="@android:color/white"
android:text="@string/save" />
<ImageView
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/ic_actionbar_logo" />
</RelativeLayout>
我在我的应用程序中使用以下主题:
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light"></style>
这是 actionbar 的初始化代码:
actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.actionbar);
getSupportActionBar()
调用之后。 - user1940676