[英]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.