【问题标题】:Android Toolbar TextView match_parent getting bigger than screenAndroid Toolbar TextView match_parent 变得比屏幕大
【发布时间】:2017-12-29 19:15:51
【问题描述】:

我有一个带有 TextView 的工具栏,里面带有 match_parent 以使文本居中,但每次我这样做时它都会变得比屏幕大并隐藏文本。

在这里你可以看到它正在运行

预览中的样子

最后我是如何实现它的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="8dp">

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

            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="@string/title_activity_anuncios" />

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

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

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.constraint.ConstraintLayout>

</LinearLayout>

【问题讨论】:

    标签: android layout center toolbar


    【解决方案1】:

    检查您的主题样式或从清单中设置活动主题

     android:theme="@android:style/Theme.Translucent.NoTitleBar" 
    

    如果活动主题正确,那么您可以检查您的活动 >> onCreate 方法。

       ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setTitle("Your Title");
        } 
    

    【讨论】:

    • 谢谢,我完全忘记了
    【解决方案2】:

    把它放在你的工具栏中

    app:contentInsetStart="0dp"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多