snackbar
程序功能
- 点击按钮,弹出snackBar
第一步:添加包
右键项目->open Settings ->dependenices-> + ->找到com.android.support.design -> ok
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:id="@+id/constraintLayout"
>
<Button
android:id="@+id/btnShowSnackBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:onClick="showSnackBar"
android:text="点击出现SnackBar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.tnt.snackbar;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
CoordinatorLayout coordinatorLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View view = findViewById(R.id.constraintLayout);
// coordinatorLayout= findViewById(R.id.coordinatorLayout);
}
public void showSnackBar(View view) {
Snackbar.make(view,"这是massage", Snackbar.LENGTH_LONG).setAction("这是action", new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"你点击了action",Toast.LENGTH_SHORT).show();
}
}).show();
}
}
相关阅读
四种App弹窗设计:Toast、Dialog、Actionbar 和 Snackba
弹窗又称为对话框,是App与用户进行交互的常见方式之一。弹窗分为模态弹窗和非模态弹窗两种,两者的区别在于需不需要用户对其进行回
Dialog和Toast,我们在日常的开发中一定非常熟悉,常常被用来作为Android应用内提示性信息的两种展示方式。然而Google在Design包中又