【问题标题】:Toolbar title issue工具栏标题问题
【发布时间】:2019-01-21 11:04:25
【问题描述】:

将标题设置为工具栏非常容易,因此我根据我的需要为工具栏设置标题,例如消息、文档等。

所以问题是当我将标题设置为例如“里程表”时,它会在末尾显示一个点。之后,当我打开键盘时,“里程表”一词会完全显示出来。

工具栏以 3 个点显示标题,以下是相同的屏幕截图。

问题:我需要做什么?显示完整的标题而不是 3 个点???

我们将不胜感激。

XML

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

    <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"/>

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

【问题讨论】:

  • 需要更多数据。您能否发布带有用点编写的文档的图像并提供一些代码
  • 嘿,我更新了问题,你能看看吗?
  • 放工具栏的xml代码
  • 添加了 xml 代码。请看一下。

标签: android android-toolbar


【解决方案1】:

我正在使用 appcompat v7 : 23.1.1 没有问题。 这是我的工具栏 xml。试试看。

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:elevation="4dp">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:background="?attr/colorPrimary"
        android:id="@+id/tb"/>
</android.support.design.widget.AppBarLayout>

【讨论】:

  • 对不起!我们使用 appcompat v7 编写了相同的代码:28.0.0 但无法正常工作。
【解决方案2】:

试试这个:

<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:id="@+id/details_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="top"
                android:title="@string/menuLabel1a"
                android:paddingTop="@dimen/padding_normal"
                style="@android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse"
                android:maxLines="1" />
    </android.support.v7.widget.Toolbar>

现在将文本设置为 TextView 它应该可以工作

【讨论】:

  • 我知道但我不会添加 textview。我已经有了工具栏,为什么我应该使用 TextView 来设置标题。