LoginSignup
2
0

More than 3 years have passed since last update.

Toolbarメモ

Posted at

StatusBar 透明化の正しい方法

Lollipopより前のバージョンでToolbarに影を表示する

API Level 21よりまえはandroid:elevationが使えないので、shapeで影を表現する。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/color_alizarin"
        android:titleTextAppearance="@color/White"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- **** Place Your Content Here **** -->

        <View
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="@drawable/toolbar_dropshadow" />
    </FrameLayout>
</LinearLayout>
toolbar_dropshadow.xml
  <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <gradient
        android:startColor="@android:color/transparent"
        android:endColor="#88333333"
        android:angle="90"/>
    </shape>
color.xml
<color name="color_alizarin">#e74c3c</color>
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0