1.导包design Snakebar就类似于吐丝跟吐丝的用法差不多
Snackbar.make(view,"我是你爹",Snackbar.LENGTH_SHORT).setAction().shou();
2.主布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="comqq.example.hasee.myapplication.MainActivity"
android:orientation="vertical"
>
<android.support.design.widget.TextInputLayout
android:id="@+id/til"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et1"
android:hint="请输入密码"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/but1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="cc"/>
<!--<android.support.design.widget.TextInputEditText-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content" />-->
</LinearLayout>
3.主函数
public class MainActivity extends AppCompatActivity {
private EditText et1;
private TextInputLayout til;
private BottomSheetDialog bott;
private View inflate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
til = (TextInputLayout)findViewById(R.id.til);
et1 = (EditText) findViewById(R.id.et1);
bott = new BottomSheetDialog(this);
inflate= View.inflate(this, R.layout.buju, null);
//给对话框设置布局
bott.setContentView(inflate);
// 设置点击返回键,能不能取消dialog
bott.setCancelable(false);
// 设置点击对话框以外,是否能取消这个对话框
bott.setCanceledOnTouchOutside(true);
}
public void cc(View view) {
switch (view.getId()) {
case R.id.but1:
// Snackbar.make(view,"我是你爹",Snackbar.LENGTH_SHORT).setAction("确定", new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// }
// }).show();
String s = et1.getText().toString();
if(TextUtils.isEmpty(s)){
//是否显示错误信息
til.setErrorEnabled(true);
til.setError("你还没有输入密码呢");
}else if(s.equals("123456")){
til.setErrorEnabled(false);
//类似于吐丝的一各功能 只不过多了确定按钮键
// Snackbar.make(view,"登陆成功",Snackbar.LENGTH_SHORT).show();
bott.show();
}else{
til.setErrorEnabled(true);
til.setError("输入密码有误!!");
}
break;
}
}
}
4.Snakebar吐丝时要用到的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是你爹"/>
</LinearLayout>