我可以在对话框中显示材料设计小吃栏吗? [英] Can I display material design Snackbar in dialog?

查看:44
本文介绍了我可以在对话框中显示材料设计小吃栏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个android应用程序.在那我想在对话框中显示材质设计Snackbar.是否有可能?如果是,那怎么办?

I am developing an android application. In that I want to display material design Snackbar in dialog. Is it possible? If yes then how?

请帮助我.

谢谢.

推荐答案

绝对有可能,您只需将对话框的视图传递给SnackBar.

It's definitely possible, you just have to pass the View of the Dialog to the SnackBar.

示例

    AlertDialog.Builder mAlertDialogBuilder = new AlertDialog.Builder(this);
    LayoutInflater inflater = this.getLayoutInflater();
    // inflate the custom dialog view
    final View mDialogView = inflater.inflate(R.layout.dialog_layout, null);
    // set the View for the AlertDialog
    mAlertDialogBuilder.setView(mDialogView);

    Button btn = (Button) mDialogView.findViewById(R.id.dialog_btn);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Pass the mDialogView to the SnackBar
            Snackbar
                    .make(mDialogView, "SnackBar in Dialog", Snackbar.LENGTH_LONG)
                    .show();
        }
    });
    AlertDialog alertDialog = mAlertDialogBuilder.create();
    alertDialog.show();

结果

注意: 无需使用CoordinatorLayout作为根.在我的示例中,我只是使用LinearLayout作为根.

Note: There's no need to use a CoordinatorLayout as the root. In my example I simply used a LinearLayout as the root.

这篇关于我可以在对话框中显示材料设计小吃栏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆