How to create semi-transparent circular toolbar / actionbar items?

Viewed 527

How would you make the items in the toolbar / actionbar with a semi-transparent circular background as seen in the latest Google Maps app (Screenshot)

enter image description here

would you add it to the item-icon itself (XML-Drawable preferred)? would you use the normal menu-xml to create it? I want to use it with a CollapsingToolbarLayout and hide the circular background when the toolbar is collapsed.

Thankful for any thoughts and tips on how to make this :)

1 Answers

add imageView to CollapsingToolbarLayout and use app:layout_collapseMode="parallax"

example:

<android.support.design.widget.AppBarLayout
    android:layout_height="200dp"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay">

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:contentScrim="?attr/colorPrimary"
    app:expandedTitleMarginEnd="64dp"
    app:expandedTitleMarginStart="48dp"
    app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways" />
          <ImageView
            android:src="@drawable/cheese_1"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            android:minHeight="100dp" />

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

in code use OnOffsetChangedListener to listen to the state of appbar expand/collapse and you can change toolbar icon items

  final AppBarLayout mAppBarLayout = findViewById(R.id.appbar);
    mAppBarLayout.addOnOffsetChangedListener(new   AppBarLayout.OnOffsetChangedListener() {
    private State state;

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if (verticalOffset == 0) {
            if (state != State.EXPANDED) {
                //change item rounded icon
            }
                state = State.EXPANDED;

        } else if (Math.abs(verticalOffset) >=   appBarLayout.getTotalScrollRange()) {
            if (state != State.COLLAPSED) {
                //change item default icon
            }
            state = State.COLLAPSED;
        } else {
            if (state != State.IDLE) {
                Log.d(TAG,"Idle");
            }
            state = State.IDLE;
        }
    }
});
Related