【问题标题】:Not full width toolbar in android studio?android studio中没有全宽工具栏?
【发布时间】:2017-03-17 02:48:19
【问题描述】:

我在我的应用程序中使用工具栏,我将 TextView 自定义到工具栏的中心,但它不是工具栏屏幕的全宽,并且在左侧保持一个小屏幕,如下图所示。那么如何才能让 Custom TextView 位于屏幕和 Toolbar 的中心呢?

我目前的屏幕问题:

我想要的屏幕:

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.Dark"
        xmlns:app="http://schemas.android.com/apk/res-auto">
        <TextView
            android:id="@+id/tv_title"
            android:textColor="#FFF"
            android:background="#F00"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="TITLE"
            android:textStyle="bold"
            android:textSize="15sp"
            android:gravity="center"/>
    </android.support.v7.widget.Toolbar>

谢谢!

【问题讨论】:

  • 发布你的代码,xml文件
  • 删除您为工具栏提供的任何左侧填充。
  • 我删除了所有的填充
  • 您的工具栏有全宽,红色元素是您的文本视图。
  • 是的@Kaushal28 我的文本视图是红色的

标签: android xml android-layout textview toolbar


【解决方案1】:

在您的ToolBar 中添加以下属性以删除左填充。

 app:contentInsetLeft="0dp"
 app:contentInsetStart="0dp"

【讨论】:

  • 你拯救了我的一天
  • 它工作正常!
猜你喜欢
  • 1970-01-01
  • 2016-08-23
  • 1970-01-01
  • 1970-01-01
  • 2017-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多