简体   繁体   English

如何在警报对话框上显示ShowCase(Android)

[英]How to display ShowCase on Alert Dialog (Android)

I've used the library com.github.mreram: showcaseview: 1.1 . 我使用了库com.github.mreram: showcaseview: 1.1

When I want to show the showcase on the alert, it shows the showcase behind the alert. 当我想在警报上显示展示柜时,它会在警报后面显示展示柜。

I've used almost all of the ShowCases but they all have the same problem. 我几乎使用了所有ShowCases,但是它们都有相同的问题。

private GuideView ShowCaseView;
private GuideView.Builder ShowCaseBuilder;
private Alert Alert;

@oClick(R.id.bTest)
public void onClick() {
    Alert = new Alert(this);
    Alert.ShowAlert();

    ImageView imgCancel = ButterKnife.findById(Alert, R.id.imgAlertTitle);

    ShowCaseBuilder = new GuideView.Builder(this)
                            .setTitle("Test")
                            .setContentText("Test")
                            .setTargetView(imgCancel)
                            .setContentTypeFace(AppController.Iran)
                            .setTitleTypeFace(AppController.IranBold)
                            .setDismissType(DismissType.anywhere)
                            .setGuideListener(new GuideListener() {
                                @Override
                                public void onDismiss(View view) {
                                    return;
                                }
                            });

      ShowCaseView = ShowCaseBuilder.build();
      if (!ShowCaseView.isShowing())
           ShowCaseView.show();
}

The result looks like this enter image description here 结果看起来像这样 在这里输入图像描述

You need to first create your own custom Dialor Alert. 您需要首先创建自己的自定义Dialor Alert。 And then include the showcase code inside it. 然后在其中包含展示代码。 Example of how to make a CustomDialogAlert: 如何制作CustomDialogAlert的示例:

https://abhiandroid.com/ui/custom-alert-dialog-example-android-studio.html https://abhiandroid.com/ui/custom-alert-dialog-example-android-studio.html

How to create a Custom Dialog box in android? 如何在android中创建自定义对话框?

Or try making a class like: 或尝试制作类似的课程:

 public class ViewDialog {

    public void showDialog(Activity activity, String msg){
        final Dialog dialog = new Dialog(activity);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(false);
        dialog.setContentView(R.layout.custom_dialogbox_otp);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

        TextView text = (TextView) dialog.findViewById(R.id.txt_file_path);
        text.setText(msg);

        Button dialogBtn_cancel = (Button) dialog.findViewById(R.id.btn_cancel);
        dialogBtn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        Button dialogBtn_okay = (Button) dialog.findViewById(R.id.btn_okay);
        dialogBtn_okay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.cancel();
            }
        });
        ShowCaseBuilder = new GuideView.Builder(this)
                        .setTitle("Test")
                        .setContentText("Test")
                        .setTargetView(imgCancel)
                        .setContentTypeFace(AppController.Iran)
                        .setTitleTypeFace(AppController.IranBold)
                        .setDismissType(DismissType.anywhere)
                        .setGuideListener(new GuideListener() {
                            @Override
                            public void onDismiss(View view) {
                                return;
                            }
                        });

        MyShowCaseView = ShowCaseBuilder.build();
        if (!ShowCaseView.isShowing())
            ShowCaseView.show();
             dialog.show();
        }
  }

Also, because of the issue pointed out by @MikeM, You need to create a class, that extends GuideView and override the show so that in the show() it adds the view in the proper place 另外,由于@MikeM指出的问题,您需要创建一个类,该类扩展GuideView并覆盖显示,以便在show()中将视图添加到正确的位置

public void show() {
    this.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    this.setClickable(false);

    ((ViewGroup) ((Activity) getContext()).getWindow().getDecorView()).addView(this);
    AlphaAnimation startAnimation = new AlphaAnimation(0.0f, 1.0f);
    startAnimation.setDuration(APPEARING_ANIMATION_DURATION);
    startAnimation.setFillAfter(true);
    this.startAnimation(startAnimation);
    mIsShowing = true;
}

My full MyGuideView I tried: 我尝试了完整的MyGuideView:

https://pastebin.com/LkES1Vih https://pastebin.com/LkES1Vih

And I do: 我做:

    ShowCaseView = new showCaseBuilder.build()
    ShowCaseView.setLayout(parentView)
    if (!ShowCaseView.isShowing())
        ShowCaseView.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM