【问题标题】:How do I create a mini layout like this in Android Studio?如何在 Android Studio 中创建这样的迷你布局?
【发布时间】:2019-05-02 00:32:33
【问题描述】:

【问题讨论】:

  • AlertDialog
  • 这是一个 AlertDialog..go 一些 AlertDialog 示例,你会明白的

标签: android android-studio android-layout


【解决方案1】:

我认为你想要做的是一个警告对话框......所以像这样

new AlertDialog.Builder(this)
                    .setTitle("Share using Wi-Fi Direct?")
                    .setCancelable(false)
                    .setMessage("You can only share folders using Wi-Fi Direct")
                    .setPositiveButton("SHARE VIA WI-FI DIRECT", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            //do what you want here
                        }
                    })
                    .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            //do what you want here
                            finish();
                        }
                    })
                    .create()
                    .show();

【讨论】:

    【解决方案2】:

    试试这个

    /* using sign out alert for app*/
    private void dialogBox() {
        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(getActivity());
        String titleText = "Share using Wi-Fi Direct?";
        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.BLACK);
        SpannableStringBuilder ssBuilder = new SpannableStringBuilder(titleText);
        ssBuilder.setSpan(
                foregroundColorSpan,
                0,
                titleText.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        );
        builder.setCancelable(false);
        builder.setTitle(ssBuilder);
    
            builder.setMessage("You can only share folders using Wi-Fi Direct");
    
    
        builder.setPositiveButton("SHARE VIA WI-FI DIRECT", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
               // your code
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        // Create the alert dialog
        android.support.v7.app.AlertDialog dialog = builder.create();
        // Finally, display the alert dialog
        dialog.show();
        // Get the alert dialog buttons reference
        Button positiveButton = dialog.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE);
        Button negativeButton = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
        // Change the alert dialog buttons text and background color
        positiveButton.setTextColor(Color.parseColor("#00aff1"));
        negativeButton.setTextColor(Color.parseColor("#00aff1"));
    }
    
    • 您正在使用警报对话框和创建自定义对话框在屏幕下方显示迷你布局

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 1970-01-01
      相关资源
      最近更新 更多