【问题标题】:How can I center the title of navigation drawer application?如何使导航抽屉应用程序的标题居中?
【发布时间】:2018-07-30 13:09:42
【问题描述】:

如何更改导航抽屉应用程序的标题位置(Android studio)?

【问题讨论】:

  • 分享你的xml代码

标签: android android-layout android-fragments


【解决方案1】:

在 Toolbar 里面插入了一个带有 gravity = "center" 的文本视图,并通过 java 禁用了默认标题。

试试下面的代码:

<android.support.design.widget.AppBarLayout
        app:elevation="0dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" >

      <TextView>
            android:layout_width="wrap_content"
            android:textSize="18dp"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="Title Here"
            android:textColor="@color/white" />

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

java 代码禁用你的标题:

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多