添加OnCreateOptions菜单的自定义操作栏不居中标题Android?
我已经创建了自定义操作栏,它有ImageView(在左边)和TextView(在右边)。但是,我在活动中有不同的片段,其中有几个片段需要在CreateOptions菜单中显示。若有onCreateOptions,则操作栏的菜单标题会被推到左侧,并且不会显示在中间 它看起来像以下操作栏+OnCreateOptions菜单: 如您所见,当添加onCreateOptions菜单时,下载文本有点向左倾斜 如果没有onCreateOptions,则文本居中,如下所示: 这是我的自定义操作条形码:添加OnCreateOptions菜单的自定义操作栏不居中标题Android?,android,android-layout,Android,Android Layout,我已经创建了自定义操作栏,它有ImageView(在左边)和TextView(在右边)。但是,我在活动中有不同的片段,其中有几个片段需要在CreateOptions菜单中显示。若有onCreateOptions,则操作栏的菜单标题会被推到左侧,并且不会显示在中间 它看起来像以下操作栏+OnCreateOptions菜单: 如您所见,当添加onCreateOptions菜单时,下载文本有点向左倾斜 如果没有onCreateOptions,则文本居中,如下所示: 这是我的自定义操作条形码: &l
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menubutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="5dp"
android:src="@drawable/navigation_icon" />
<TextView
android:id="@+id/titleofscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#22c064"
android:textSize="22sp"
android:textStyle="bold" />
</RelativeLayout>
我不想在自定义操作栏中将CreateOptions菜单设置为imageView,因为这会使事情变得复杂。试试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menubutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="5dp"
android:src="@drawable/navigation_icon" />
<TextView
android:id="@+id/titleofscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/menubutton"
android:gravity="center"
android:textColor="#22c064"
android:textSize="22sp"
android:textStyle="bold" />
</RelativeLayout>
@vo12这次尝试与右图对齐。希望它能解决您的问题。答案编辑您看过API 21中的工具栏了吗?我注意到你有五个问题,包括这一个,你要求优先处理其他问题。请不要这样做-请记住,这里的读者主要是志愿者,他们会在空闲时回答他们感兴趣的问题。谢谢