Snackbar 提醒

时间:2021-04-22 14:39:22

类似于Toast,属于design包,不要忘记导入design

package com.xiaozhuyisheng.jinjiedemos.activity;

import android.support.design.widget.Snackbar;
import android.view.View; import com.xiaozhuyisheng.jinjiedemos.BaseActivity;
import com.xiaozhuyisheng.jinjiedemos.R; import butterknife.BindView; // implementation 'com.android.support:design:28.0.0' public class SnackbarDemoActivity extends BaseActivity {
@BindView(R.id.testView)
View testView; @Override
protected int initLayoutID() {
return R.layout.activity_snacker;
} @Override
protected void initLogic() {
findViewById(R.id.btnHint).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showSnackbar();
}
});
} private void showSnackbar() {
Snackbar.make(testView,"标题",Snackbar.LENGTH_SHORT)
.setAction("点击事件", new View.OnClickListener() {
@Override
public void onClick(View view) { }
}).setDuration(Snackbar.LENGTH_LONG).show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提示"
android:id="@+id/btnHint"
/> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/testView"
> </LinearLayout> </android.support.constraint.ConstraintLayout>