Android L FAB Button shadow

前端 未结 3 2001
名媛妹妹
名媛妹妹 2020-12-12 18:50

In the Material Design guidelines Google presented a new style of button, the FAB Button. I found instructions how to make it but I have trouble adding the shadow.

3条回答
  •  天涯浪人
    2020-12-12 19:03

    Check out the "activity.java", there is probably the code you need.

    I made the Fab - Button like this:

    layout.xml

        

    ripple.xml

    
     
     
    
    

    fab.xml

    
      
      
    
    

    Activity.java

        import android.graphics.Outline;
        ...
        Button fab = (Button) rootView.findViewById(R.id.fabbutton);
    
        Outline mOutlineCircle;
        int shapeSize = getResources().getDimensionPixelSize(R.dimen.shape_size);
        mOutlineCircle = new Outline();
        mOutlineCircle.setRoundRect(0, 0, shapeSize, shapeSize, shapeSize / 2);
    
        fab.setOutline(mOutlineCircle);
        fab.setClipToOutline(true);
    

    This code will be shown as error in android studio v0.8.1, so as other android l components. It will be fixed in the next version.

    Result:

    enter image description here

提交回复
热议问题