Skip to content

Commit

Permalink
Add fab example
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa committed Apr 26, 2016
1 parent 3db46ed commit 450fe50
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import android.os.Bundle;
import android.support.annotation.MenuRes;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.widget.Toolbar;
Expand All @@ -21,6 +23,7 @@ public class MainActivity extends AppCompatActivity
private BottomSheetDialog mBottomSheetDialog;
private View mBottomSheet;
private BottomSheetBehavior mBehavior;
private FloatingActionButton mFab;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -33,6 +36,8 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.showViewBtn).setOnClickListener(this);
findViewById(R.id.showDialogBtn).setOnClickListener(this);
findViewById(R.id.showDialogHeadersBtn).setOnClickListener(this);
mFab = (FloatingActionButton) findViewById(R.id.fab);
mFab.setOnClickListener(this);

CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);

Expand All @@ -47,6 +52,20 @@ protected void onCreate(Bundle savedInstanceState) {
.createView();

mBehavior = BottomSheetBehavior.from(mBottomSheet);
mBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN
|| newState == BottomSheetBehavior.STATE_COLLAPSED) {
mFab.show();
}
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {

}
});
}

@Override
Expand Down Expand Up @@ -85,7 +104,14 @@ public void onClick(View v) {
if (v.getId() == R.id.showDialogHeadersBtn) {
mBottomSheetDialog = createDialog(R.menu.menu_bottom_headers_sheet);
mBottomSheetDialog.show();
return;
}

if (v.getId() == R.id.fab) {
mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
mFab.hide();
}

}

@Override
Expand Down
9 changes: 9 additions & 0 deletions sample/src/main/res/drawable/ic_share_white_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>
9 changes: 7 additions & 2 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@

</android.support.design.widget.AppBarLayout>



<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_share_white_24dp" />


</android.support.design.widget.CoordinatorLayout>

0 comments on commit 450fe50

Please sign in to comment.