Skip to content

Instantly share code, notes, and snippets.

@lynfogeek
Forked from gabrielemariotti/Activity.java
Created October 23, 2014 10:19
Show Gist options
  • Save lynfogeek/6699fb459a706efdba14 to your computer and use it in GitHub Desktop.
Save lynfogeek/6699fb459a706efdba14 to your computer and use it in GitHub Desktop.

Revisions

  1. lynfogeek revised this gist Oct 23, 2014. 2 changed files with 8 additions and 5 deletions.
    11 changes: 7 additions & 4 deletions Activity.java
    Original file line number Diff line number Diff line change
    @@ -6,10 +6,13 @@ protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.layoutfab);

    //Outline
    int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
    Outline outline = new Outline();
    outline.setOval(0, 0, size, size);
    findViewById(R.id.fab).setOutline(outline);
    final int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
    findViewById(R.id.fab).setOutlineProvider(new ViewOutlineProvider() {
    @Override
    public void getOutline(View view, Outline outline) {
    outline.setOval(0, 0, size, size);
    }
    });
    }

    }
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    **Floating Action Button** (requires Android-L preview)
    **Floating Action Button** (requires Android-5.0 Lollipop)
  2. @gabrielemariotti gabrielemariotti revised this gist Sep 4, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    **Floating Action Button** (requires Android-L preview)
  3. @gabrielemariotti gabrielemariotti created this gist Jul 2, 2014.
    15 changes: 15 additions & 0 deletions Activity.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layoutfab);

    //Outline
    int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
    Outline outline = new Outline();
    outline.setOval(0, 0, size, size);
    findViewById(R.id.fab).setOutline(outline);
    }

    }
    20 changes: 20 additions & 0 deletions anim.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
    android:state_enabled="true"
    android:state_pressed="true">
    <objectAnimator
    android:duration="@android:integer/config_shortAnimTime"
    android:propertyName="translationZ"
    android:valueFrom="@dimen/button_elevation"
    android:valueTo="@dimen/button_press_elevation"
    android:valueType="floatType" />
    </item>
    <item>
    <objectAnimator
    android:duration="@android:integer/config_shortAnimTime"
    android:propertyName="translationZ"
    android:valueFrom="@dimen/button_press_elevation"
    android:valueTo="@dimen/button_elevation"
    android:valueType="floatType" />
    </item>
    </selector>
    6 changes: 6 additions & 0 deletions dimens.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <resources>
    <dimen name="fab_size">56dp</dimen>

    <dimen name="button_elevation">2dp</dimen>
    <dimen name="button_press_elevation">4dp</dimen>
    </resources>
    23 changes: 23 additions & 0 deletions layoutfab.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageButton
    android:id="@+id/fab"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:layout_width="@dimen/fab_size"
    android:layout_height="@dimen/fab_size"
    android:layout_gravity="bottom|right"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="16dp"
    android:background="@drawable/ripple"
    android:stateListAnimator="@anim/anim"
    android:src="@drawable/ic_action_add"
    android:elevation="4dp"
    />


    </RelativeLayout>
    7 changes: 7 additions & 0 deletions ripple.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight">
    <item>
    <shape android:shape="oval">
    <solid android:color="?android:colorAccent" />
    </shape>
    </item>
    </ripple>