Help us understand the problem. What is going on with this article?

ToolbarにTabLayoutをもたせてみる

More than 1 year has passed since last update.

ToolbarはViewを内部に持つことが可能
なので

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    >
    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="64dp"
        android:layout_marginRight="64dp"
        android:background="@android:color/background_light"
        app:tabGravity="fill"
        app:tabMode="scrollable"
        app:tabIndicatorColor="@color/colorPrimary"
        app:tabIndicatorHeight="2dp"
        />
</androidx.appcompat.widget.Toolbar>

のようにしてToolbarの中にTabを作る事もできる。

device-2018-11-29-201347.png

両サイドに透過グラデーションをつけたdrawableを背景にしたViewを配置して、すみっこに行った時に消えるような感じ

<androidx.appcompat.widget.Toolbar
     android:id="@+id/toolbar"
     android:layout_width="match_parent"
     android:layout_height="?attr/actionBarSize"
     android:background="@color/colorPrimary"
     >
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_marginLeft="64dp"
         android:layout_marginRight="64dp"
         >
         <com.google.android.material.tabs.TabLayout
             android:id="@+id/tab_layout"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_gravity="center_horizontal"
             app:tabGravity="fill"
             app:tabMode="scrollable"
             app:tabIndicatorColor="@color/colorPrimary"
             app:tabIndicatorHeight="2dp"
             android:background="@android:color/background_light"
             />
         <View
             android:layout_width="52dp"
             android:layout_height="match_parent"
             android:background="@drawable/gradation_left"
             android:layout_gravity="start"
             />
         <View
             android:layout_width="52dp"
             android:layout_height="match_parent"
             android:background="@drawable/gradation_right"
             android:layout_gravity="end"
             />
     </FrameLayout>
  </androidx.appcompat.widget.Toolbar>

device-2018-11-29-202111.png

やってみたけどToolbarの中でやる必要は無いと思う。FrameLayoutで重ねても出来るし。
NavigationDrawerとかCollapsingToolbarLayoutを使っている時に使えるかもしれない?いやないか

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away