动作条标题为中心的按钮 [英] Actionbar centered title with buttons
问题描述
我想在中心操作栏的冠军,而其操作图标旁边(而忽略他们的重心设置)。
I would like to center the title in the action bar, while having action icons next to it(and ignoring them for the gravity setting).
我想有这样的:
I would like to have this:
相反,我有这样的:
Instead I have this:
下面是我的code:
ActionBar actionBar = getSupportActionBar();
ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.top_bar));
actionBar.setCustomView(LayoutInflater.from(this).inflate(R.layout.actionbar_layout, null), params);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
我的布局:
<?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:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="8dp"
android:src="@drawable/launcher_icon" />
<TextView
android:id="@+id/actionbar_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:maxHeight="1dp"
android:maxLines="1"
android:paddingLeft="48dp"
android:paddingRight="48dp"
android:text="Bacon ipsum"
android:textColor="#777777"
android:textSize="20sp" />
</RelativeLayout>
所以,我的问题是,围绕称号只适用,如果我有0动作条的项目旁边,当我加入一个项目,对中被搞砸了。 这也将是巨大的,如果我可以用它向上启示按钮(也砸了,现在定心)。
So my problem is, centering the title only works, if I have 0 actionbar items next to it, as soon as I add an item, the centering gets screwed up. It would also be great, if I could use the up affordance button with it(which also screws up the centering now).
任何帮助将是AP preciated。
Any help would be appreciated.
我不婉实现我自己的动作条项目/按钮逻辑。
I don't wan to implement my own actionbar item/button logic.
推荐答案
您可以在TextView中试试这个:
You can try this in the TextView:
<TextView
android:id="@+id/actionbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:maxHeight="1dp"
android:maxLines="1"
android:paddingLeft="48dp"
android:paddingRight="48dp"
android:text="Bacon ipsum"
android:textColor="#777777"
android:textSize="20sp" />
这篇关于动作条标题为中心的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!