Android 使用Snackbar跟CoordinatorLayout
build.gradle
dependencies {
compile 'com.android.support:design:24.2.1'
}
activity_main.xml布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:onClick="createSnackbar"
android:text="@string/snackbar_test_button_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
MainActivity
container = (CoordinatorLayout) findViewById(R.id.container);
Snackbar.make(container, "This is explanation: Please give us permission", Snackbar.LENGTH_LONG)
.setAction("OK", new View.OnClickListener() {
@Override
public void onClick(View view) {
requestExternalStoragePermission();
}
}).show();
沒有留言:
張貼留言