Rikki Tikki Tavi Rikki Tikki Tavi - 5 months ago 158
Android Question

Material Design : how to set transparency for Android Floating Action Button

My question is related to this one.

When I open the NavigationDrawer, the Floating Button is on the top of it but has to be below.

I try to do it like that :

@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
Log.i(TAG , " inner onDrawerSlide");
super.onDrawerSlide(drawerView, slideOffset);
fabButton.setAlpha(25);
float alpha = 0.2f;
AlphaAnimation alphaUp = new AlphaAnimation(alpha, alpha);
alphaUp.setFillAfter(true);
fabButton.startAnimation(alphaUp);
syncState();
}


and like that :

@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerClosed(view);
invalidateOptionsMenu();
fabButton.setAlpha(255);
syncState();
}


Nothing worked for me. What can be the solution ?

My layout:

<mobapply.freightexchange.customviews.FragmentNavigationDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">

<!-- The ActionBar -->
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<!-- The main content view -->
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- The navigation drawer -->
<ListView
android:id="@+id/lvDrawer"
android:layout_width="match_parent"
android:divider="@null"
android:dividerHeight="0dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:background="#FFFFFF"
android:cacheColorHint="@android:color/transparent"
/>




FragmentNavigationDrawer is the custom
DrawerLayout

Answer

From the Android documentation for setAlpha(float alpha) (since API 11):

Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

You're trying to set it to value 25 or 255 :)