アップデート:
Google I/O 2015 以降、デザイン サポート ライブラリを使用して、フローティング アクション ボタン (FAB) などのマテリアル デザイン ビューを実現できます。以下Toolbar
に示すように、v7 サポート ライブラリを使用して作成されます。
の設計Toolbar
:
Google のこれらの仕様とガイドラインを見Toolbar
て、正しい仕様と測定値を使用して、自分が望む方法で拡張を設定することができました。
私の場合、Fragment
s を使用してメイン コンテンツを変更していたので (Views
内部の拡張Toolbar
も異なります)、アクティビティ用のレイアウト ファイルと、他のフラグメント用の別のレイアウト ファイルがありました。私の主な活動のレイアウトは次のとおりです。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/main_toolbar" layout="@layout/toolbar" />
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/main_toolbar" />
</RelativeLayout>
は@layout/toolbar
単に次のレイアウトを参照しています (標準のツールバーに使用していたレイアウト(つまり、通常の高さ、 のようにActionBar
)):
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
FrameLayout
また、 (メイン アクティビティのレイアウトの)コンテンツはJava で変更されます。私のフラグメントの 1 つは 2 つSpinner
の を必要とし、これらを拡張された に埋め込みたいと思いましたToolbar
。はToolbar
として便利に使用できるため、フラグメントの 1 つに次のレイアウトViewGroup
を作成して使用しました。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/extended_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:contentInsetStart="72dp"
app:contentInsetEnd="16dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center_horizontal"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
<include layout="@layout/toolbar_space_margin" />
<Spinner
android:id="@+id/spinner_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Spinner
android:id="@+id/spinner_two
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"/>
<include layout="@layout/toolbar_space_margin" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/extended_toolbar" >
<!-- The main content of that activity layout -->
</ScrollView>
</RelativeLayout>
は、 で定義した?attr/colorPrimary
原色 ( ) を指します。との 2 つの属性は、 のパディングのようなものだと思います。これは、がの左端から、右端からもあることを意味します。また、上下の余白に使用した基本的に空のビューを 2 回参照しました。colorPrimary
styles.xml
contentInsetStart
contentInsetEnd
Toolbar
LinearLayout
72dp
Toolbar
16dp
@layout/toolbar_space_margin
<?xml version="1.0" encoding="utf-8"?>
<Space
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="16dp" />
フローティング アクション ボタンの使用:
フローティングアクションボタンの使い方については、いろいろなチュートリアルやスタックオーバーフローの投稿を見つけたので、そちらを利用しました。質問のその部分をもう少しよく調べるべきだった...
デザインでこの問題に遭遇した他の人が、この回答が役立つことを願っています.