3
我使用的是Android(4.0或更高版本)。我想使用操作栏和操作栏的标题靠近图标。我想标题将中心和大胆,因为它在图片上 Android标题标题集中心位置
我使用的是Android(4.0或更高版本)。我想使用操作栏和操作栏的标题靠近图标。我想标题将中心和大胆,因为它在图片上 Android标题标题集中心位置
您应该为ActionBar
进行自定义布局。
在Java:
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getActionBar().setCustomView(R.layout.actionbar);
在XML(这将是R.layout.actionbar):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="YOUR ACTIVITY TITLE"
android:textStyle="bold"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
您可以然后把更多的东西在动作条XML如果你想。
您需要设置具有自定义布局的操作栏。 像这样根据您的需要
action = getActionBar();
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL
| Gravity.CENTER_VERTICAL);
View v = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.customlayout, null);
action.setCustomView(v, lp);
action.setDisplayShowCustomEnabled(true);
action.setDisplayHomeAsUpEnabled(true);
action.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
注修改代码:您需要创建自定义布局:R.layout.customlayout。
谢谢你的回复,但是这里没有后退按钮 – javagc
尝试用'getActionBar()。setDisplayHomeAsUpEnabled(true);' – ArianJM
结果是一样的:( – javagc