Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2,FAB and Snackbar 示例
- Loading branch information
zhouwei
committed
Dec 22, 2016
1 parent
35687dd
commit 43cb516
Showing
11 changed files
with
256 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../main/java/com/zhouwei/md/materialdesignsamples/behavoir/BottomSheetBehaviorActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.zhouwei.md.materialdesignsamples.behavoir; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.design.widget.BottomSheetBehavior; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
|
||
import com.zhouwei.md.materialdesignsamples.R; | ||
|
||
/** | ||
* Created by zhouwei on 16/12/20. | ||
*/ | ||
|
||
public class BottomSheetBehaviorActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.bottom_sheet_behavior_ac); | ||
|
||
View shareView = findViewById(R.id.share_view); | ||
//获取BottomSheetBehavior | ||
final BottomSheetBehavior sheetBehavior = BottomSheetBehavior.from(shareView); | ||
|
||
//设置折叠时的高度 | ||
//sheetBehavior.setPeekHeight(BottomSheetBehavior.PEEK_HEIGHT_AUTO); | ||
|
||
//监听BottomSheetBehavior 状态的变化 | ||
sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { | ||
@Override | ||
public void onStateChanged(@NonNull View bottomSheet, int newState) { | ||
|
||
} | ||
|
||
@Override | ||
public void onSlide(@NonNull View bottomSheet, float slideOffset) { | ||
|
||
} | ||
}); | ||
|
||
//下滑的时候是否可以隐藏 | ||
sheetBehavior.setHideable(true); | ||
findViewById(R.id.btn_show_bottom_sheet).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if(sheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED){ | ||
sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); | ||
}else { | ||
sheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); | ||
} | ||
|
||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
app/src/main/java/com/zhouwei/md/materialdesignsamples/behavoir/FABSimpleActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.zhouwei.md.materialdesignsamples.behavoir; | ||
|
||
import android.content.res.ColorStateList; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.design.widget.Snackbar; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
import com.zhouwei.md.materialdesignsamples.R; | ||
|
||
/** | ||
* Created by zhouwei on 16/12/20. | ||
*/ | ||
|
||
public class FABSimpleActivity extends AppCompatActivity { | ||
private static final String TAG = "FABSimpleActivity"; | ||
private FloatingActionButton fab1,fab2; | ||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.fab_simple_layout); | ||
|
||
fab1 = (FloatingActionButton) findViewById(R.id.fab1); | ||
fab2 = (FloatingActionButton) findViewById(R.id.fab2); | ||
|
||
fab1.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Snackbar.make(fab1,"点击fab1",Snackbar.LENGTH_LONG).show(); | ||
} | ||
}); | ||
|
||
fab1.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary))); | ||
|
||
|
||
fab2.setImageResource(R.drawable.ic_book_list); | ||
|
||
fab2.setCompatElevation(6); | ||
|
||
fab2.setSize(FloatingActionButton.SIZE_NORMAL); | ||
fab2.hide(new FloatingActionButton.OnVisibilityChangedListener() { | ||
@Override | ||
public void onHidden(FloatingActionButton fab) { | ||
Log.i(TAG,"fab hidden..."); | ||
} | ||
}); | ||
fab2.show(new FloatingActionButton.OnVisibilityChangedListener() { | ||
@Override | ||
public void onShown(FloatingActionButton fab) { | ||
Log.i(TAG,"fab show..."); | ||
} | ||
}); | ||
|
||
fab2.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Snackbar.make(fab2,"哈哈,我是Snackbar2",Snackbar.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<TextView | ||
android:id="@+id/btn_show_bottom_sheet" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="显示/隐藏 BottomSheet" | ||
android:background="@android:color/darker_gray" | ||
android:textColor="@color/black" | ||
android:padding="10dp" | ||
/> | ||
<FrameLayout | ||
android:id="@+id/share_view" | ||
app:layout_behavior="@string/bottom_sheet_behavior" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@android:color/white" | ||
android:orientation="vertical" | ||
app:behavior_peekHeight="0dp" | ||
> | ||
<include layout="@layout/bottom_sheet_share_dialog"/> | ||
</FrameLayout> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<android.support.design.widget.AppBarLayout | ||
android:id="@+id/appbar_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<android.support.design.widget.CollapsingToolbarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="200dp" | ||
app:layout_scrollFlags="scroll|exitUntilCollapsed" | ||
> | ||
<ImageView | ||
android:layout_width="match_parent" | ||
android:layout_height="200dp" | ||
android:src="@drawable/meizhi" | ||
android:scaleType="centerCrop" | ||
app:layout_collapseMode="parallax" | ||
/> | ||
<android.support.v7.widget.Toolbar | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
app:layout_collapseMode="pin" | ||
/> | ||
</android.support.design.widget.CollapsingToolbarLayout> | ||
</android.support.design.widget.AppBarLayout> | ||
<android.support.v4.widget.NestedScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" | ||
> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="18dp" | ||
android:text="@string/large_text"/> | ||
|
||
</android.support.v4.widget.NestedScrollView> | ||
<android.support.design.widget.FloatingActionButton | ||
android:id="@+id/fab1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@android:drawable/ic_dialog_email" | ||
android:layout_marginBottom="20dp" | ||
android:layout_marginRight="15dp" | ||
android:layout_gravity="bottom|right" | ||
app:rippleColor="@android:color/darker_gray" | ||
/> | ||
<android.support.design.widget.FloatingActionButton | ||
android:id="@+id/fab2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@android:drawable/ic_dialog_email" | ||
android:layout_marginBottom="20dp" | ||
android:layout_marginRight="15dp" | ||
app:layout_anchor="@+id/appbar_layout" | ||
app:layout_anchorGravity="bottom|right" | ||
/> | ||
</android.support.design.widget.CoordinatorLayout> |