android - 如何在工具栏中正确添加自定义 View ?

标签 android android-toolbar

我在工具栏中添加了一个自定义 View ,但它没有使用完整的工具栏宽度,而是从左侧留出了空间。

代码 fragment

<android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="@color/colorPrimary">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorAccent">

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

从此代码 fragment 获取 View

谁能告诉我为什么它没有使用全宽的工具栏?

enter image description here

最佳答案

在您的工具栏中添加这 4 个属性,它应该可以帮助您覆盖该效果

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

如果这对您有帮助,请告诉我。

关于android - 如何在工具栏中正确添加自定义 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39717517/

相关文章:

java - 在同一 Activity 中从工具栏搜索 View 获取查询字符串?

android - 如何从工具栏中的标题中删除填充?

android - 在文件 :///android_asset/www/cordova-2. 0.0.js:938 中找不到 phonegap 类

android - 工具栏后退按钮功能

java - fragment 上的 fragment 中的 getArgs() 为 null

android - 如何将 Picture 对象转换为 Bitmap 对象,Android

android - 工具栏没有为 MenuItems 着色

Android 工具栏覆盖内容

android - 如何模拟应用程序更新

android - Visual Studio/Xamarin OnClickListener