为什么Snackbar没有显示在我的应用程序中?

时间:2018-10-07 19:01:21

标签: android snackbar

在我的应用程序中,添加一个确认对话框。用户单击“是”后,它应该上传一些日期。然后显示Snackbar。该小吃店有一个按钮。 Snackbar没有显示在我的应用程序中。我的代码有什么问题?我怀疑我为Snackbar传递视图的方式不正确。请帮助我。

private void confirmeSaveInAzuere( ContentValues values){
    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    adb.setTitle("Confirmation");
    adb.setMessage("Do you want to upload note to Azure?");
    adb.setIcon(R.mipmap.ic_warning_black_24dp);
    adb.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Utility.hideKeyboard(NoteEditorActivity.this);
            PhotoLocationNote photoLocationNote = new PhotoLocationNote();
            photoLocationNote.setData(values);
            saveInAzureDb(photoLocationNote); // Uplaod is fine.
            // this toast also not showing.
            Toast.makeText(NoteEditorActivity.this, "Note data uploaded to Azure!", Toast.LENGTH_LONG).show(); 
            // I suspect the way I get the view is not correct
            View v = findViewById(R.id.note_editor).getRootView();
            LinearLayout linearLayout = findViewById(R.id.note_editor);
           // I tried both View v  and  LinearLayout linearLayout in the sanckbar, it didn't work
            Snackbar snackbar = Snackbar
                    .make(v, "All data saved!", Snackbar.LENGTH_LONG)
                    .setAction("Show all Lists", new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            startActivity(new Intent(NoteEditorActivity.this, NoteListActivity.class));
                        }
                    });

            snackbar.show();
            return;
        }
    });
    adb.setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            return;
        } });
    adb.show();
}

我发现在对话框外调用Scnckbar可以正常工作。但这在对话框中不起作用。

0 个答案:

没有答案