【问题标题】:Android Toolbar : Centre align a TextView in a toolbar having a menuAndroid工具栏:居中对齐具有菜单的工具栏中的TextView
【发布时间】:2016-02-16 17:56:42
【问题描述】:

我的活动中有一个工具栏(未设置为操作栏)。我已经添加了一个菜单项。

toolBar.setOnMenuItemClickListener(
            new Toolbar.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    // Handle the menu item

                    return true;
                }
            });

toolBar.inflateMenu(R.menu.menu_main);

这减少了工具栏的大小,导致我的文本视图不再看起来像水平居中。

如何在工具栏中居中对齐(至少让它看起来像)这个文本视图,同时保留我添加的菜单项/项目?

【问题讨论】:

    标签: android alignment android-toolbar


    【解决方案1】:

    添加属性 app:contentInsetEnd="0dp"app:contentInsetStart="0dp" 属性在我的布局中的工具栏小部件 为我解决了这个问题。

    <android.support.v7.widget.Toolbar  
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolBar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/transparent"
        android:minHeight="?attr/actionBarSize"
     app:contentInsetEnd="0dp"
    app:contentInsetStart="0dp">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      相关资源
      最近更新 更多