Android:如何集中活动标签

问题描述 投票:2回答:1

我想让标签(我的应用程序)在操作栏中集中对齐。我应该怎么做?

这是当前的屏幕:

android android-actionbar label
1个回答
9
投票

如果你正在使用Toolbar,你可以试试这个:

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize">
 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="My App"
    android:layout_gravity="center"
    android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>

如果你正在使用ActionBar试试这个:

在你的onCreate()中添加:

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
getSupportActionBar().setCustomView(R.layout.your_LAYOUT);

your_LAYOUT应该像:

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="myApp"
    android:id="@+id/tvtitle" />

© www.soinside.com 2019 - 2024. All rights reserved.