簡體   English   中英

后退按鈕和搜索視圖之間的空間太大-是否可以在工具欄上縮小它?

[英]The space between the back button and the search view is too much - is it possible to reduce it on the toolbar?

工具欄

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
              android:layout_height="wrap_content" xmlns:card_view="http://schemas.android.com/tools"
              android:orientation="vertical"
              xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto">
    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:background="@color/colorPrimary"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:gravity="center"
            app:theme="@style/ToolBarStyle">

        <TextView
                android:id="@+id/toolbar_title"
                style="@style/style_toolbar_textView" />

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

    <View style="@style/style_toolbar_shadow" />
</LinearLayout>

menu_events_ppl_list.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">

    <item android:id="@+id/menuSearchId"
          app:showAsAction="always"
          android:icon="@drawable/search_material"
          android:title="@string/str_search"
          app:actionViewClass="android.support.v7.widget.SearchView" />
</menu>

/** Init On create options menu **/
    private fun initOnCreateOptionsMenu(menu: Menu) {
        val inflater: MenuInflater = menuInflater
        inflater.inflate(R.menu.menu_events_ppl_list, menu)

        val search = toolbar.menu.findItem(R.id.menuSearchId).actionView as SearchView
        search.queryHint = "Search People";
        //search.setOnQueryTextListener(this);
        search.isIconified = false
        search.maxWidth = Integer.MAX_VALUE;
    }

我要顯示的內容

在此處輸入圖片說明

顯示什么

在此處輸入圖片說明

在Android中,后退按鈕和搜索視圖之間的空間更大,可以減少它嗎?

默認情況下,工具欄的后退按鈕后有16dp插入。 因此,在工具欄中包含app:contentInsetStartWithNavigation="0dp" ,它將刪除該空白。

<androidx.appcompat.widget.Toolbar
   ..........
   ..........
   app:contentInsetStartWithNavigation="0dp"
   ..........
   ..........
</androidx.appcompat.widget.Toolbar>

原始答案在這里

更改菜單xml的showAsAction 這正是您想要的。

app:showAsAction="ifRoom|collapseActionView"

暫無
暫無

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

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