ツールバーシリーズの記事のナビゲーション
AndroidのナビゲーションバーにあるオーバーフローメニューOverflowMenu
Androidのナビゲーションバーの検索ボックスSearchView
Androidのナビゲーションバーのカスタムナビゲーションレイアウト
AndroidでのナビゲーションバーのタブナビゲーションとTabLayoutの使用法
ツールバーのさまざまな使用法について説明する前に、現時点では、魂の拷問を送った小さなパートナーがいます。それはあまりにも醜いです、それは本当に醜いです。何?要件が非常に高いため、ズームインしてレイアウトのカスタマイズを開始することしかできません。実際には非常に単純で、独自のレイアウトをツールバーコンテナに追加するだけです。サンプルコードは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<androidx.appcompat.widget.Toolbar
app:contentInsetStartWithNavigation="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tl_head">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="中间"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左边"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="右边"/>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</LinearLayout>
このようにして、ツールバーに3つのテキストを定義しました。日付ピッカーなどの機能を定義したり、独自のタイトルをカスタマイズしたりすることもできます。右側にアイコンボタンを定義することもできます。