Skip to content

Instantly share code, notes, and snippets.

@vivekgidmare
Last active October 20, 2015 09:40
Show Gist options
  • Select an option

  • Save vivekgidmare/45bc13f621bda1b5b860 to your computer and use it in GitHub Desktop.

Select an option

Save vivekgidmare/45bc13f621bda1b5b860 to your computer and use it in GitHub Desktop.
Transparent StatusBar,Actionar Hack
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/offer_list_collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed|enterAlways">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray_fb"
android:fitsSystemWindows="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_theme_products"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/error_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text=""
android:textColor="@color/text_color_gray"
android:textSize="18sp"
android:visibility="gone" />
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/extended_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_size"
android:fitsSystemWindows="true"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.v4.widget.DrawerLayout>
@vivekgidmare

Copy link
Copy Markdown
Author

Java Code

    toolbar = (Toolbar) findViewById(R.id.extended_toolbar);
    toolbar.setPadding(0, CommonUtils.getStatusBarHeight(this), 0, 0);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
     actionBar.setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(8);
    }
   //Code for transparent actionbar and status bar
    actionBarDrawable = new ColorDrawable(getResources().getColor(R.color.action_bar_color));
    actionBarDrawable.setAlpha(0);
    toolbar.setBackgroundDrawable(actionBarDrawable);
    setStatusBarColor(0);

   recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            try {
                scrolledDistance += dy;
                final int headerHeight = (int) CommonUtils.convertDpToPixel(180, ThemeDetailsActivity.this);
                final float ratio = (float) Math.min(Math.max(scrolledDistance, 0), headerHeight) / headerHeight;
                int alpha = (int) (ratio * 255);

                actionBarDrawable.setAlpha(alpha);
                toolbar.setBackgroundDrawable(actionBarDrawable);
                setStatusBarColor(alpha);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);

        }
    });
   ```java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment