簡體   English   中英

如何刪除工具欄周圍的多余空間

[英]How can I remove the extra space around the toolbar

對該庫的示例應用程序進行了少許更改以支持可滾動的工具欄之后,它周圍留有一些空間,我不知道為什么。

在此處輸入圖片說明

此選項卡的布局文件(tab_text_view.xml):

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@null">

    <de.mrapp.android.util.view.UnfocusableToolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:background="@android:color/transparent"
      android:focusable="false"
      android:theme="?attr/toolbarTheme"
      app:layout_scrollFlags="scroll|enterAlways|snap"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

      <TextView
        android:id="@+id/file_title"
        android:layout_width="175dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="55dp"
        android:ellipsize="marquee"
        android:gravity="center_vertical"
        android:singleLine="true"
        android:text="@string/file_title"
        android:fitsSystemWindows="true"
        app:contentInsetEnd="0dp"
        app:contentInsetStart="0dp"
        android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" />

    </de.mrapp.android.util.view.UnfocusableToolbar>

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

  <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:padding="@dimen/tab_padding"
        android:text="@string/lorem_ipsum"/>

  </android.support.v4.widget.NestedScrollView>

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

我只在MainActivity添加了導航圖標,它是單擊偵聽器。 這可能是插圖問題嗎?

如果工具欄中文本的左側有空格,可以通過在第一個TextView刪除此行來刪除它:

android:layout_marginLeft="55dp"

如果這不是您想要的,可以提供屏幕截圖,這樣我就可以更好地了解不需要的空間在哪里。

在工具欄中使用contentInsetLeftcontentInsetStart

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary">

     <de.mrapp.android.util.view.UnfocusableToolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:contentInsetLeft="0dp"
                    app:contentInsetStart="0dp"
                    app:popupTheme="@style/AppTheme.PopupOverlay">

將以下代碼添加到工具欄

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

如果不起作用,請在普通工具欄中對其進行測試,如果起作用,則意味着問題來自庫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM