Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 521
Rikki Tikki Tavi Avatar asked Apr 20 '15 08:04

Rikki Tikki Tavi


People also ask

How do I add color to my floating action button?

To change background color of Floating Action Button in Kotlin Android, set the backgroundTint attribute (in layout file) or backgroundTintList property (in Kotlin file) of FAB with the required color.

How do you give padding to the floating action button in flutter?

floatingActionButton: Padding( padding: const EdgeInsets. all(8.0), child: Visibility( visible: buttonshow, child: FloatingActionButton( onPressed: () { scrollToTop(); }, shape: const StadiumBorder( side: BorderSide(color: Color(0xff135888), width: 2.5)), backgroundColor: Colors.


1 Answers

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 :)

like image 168
Bartek Lipinski Avatar answered Dec 15 '22 00:12

Bartek Lipinski