回到活动后仅显示对话框

时间:2018-12-25 05:04:44

标签: java android dialog

这是我制作的显示对话框的方法: 弹出窗口本身可以很好地工作,但是仅当我离开并返回mainActivity时才弹出,所以我猜它仅在onResume方法之后才能工作。 (“ rewardDialog”已在mainActivity类中启动,如下所示:

对话框rewardDialog;

-然后在onCreate之后-

rewardDialog.setContentView(R.layout.rewardpopup);)

    public void showRewardPopup(View v) {

    TextView close;
    final TextView claim;
    final TextView newReward;
    final TextView done;
    final TextView congrats;
    final ImageView bronzeTrophy;
    final ImageView silverTrophy;
    final ImageView goldTrophy;


    container.addEmoji(R.drawable.confetti);

    //close
    close = rewardDialog.findViewById(R.id.done);
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            rewardDialog.dismiss();
        }
    });

    //hide to go to next screen
    claim = rewardDialog.findViewById(R.id.claim);
    newReward= rewardDialog.findViewById(R.id.newReward);
    done = rewardDialog.findViewById(R.id.done);
    congrats = rewardDialog.findViewById(R.id.congrats);
    bronzeTrophy = rewardDialog.findViewById(R.id.bronzeTrophy);
    silverTrophy = rewardDialog.findViewById(R.id.silverTrophy);
    goldTrophy = rewardDialog.findViewById(R.id.goldTrophy);

    //show popup
    rewardDialog.getWindow().getAttributes().windowAnimations = R.style.popUpAnimation;
    rewardDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    rewardDialog.show();

    claim.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            claim.setVisibility(View.GONE);
            newReward.setVisibility(View.GONE);
            done.setVisibility(View.VISIBLE);
            congrats.setVisibility(View.VISIBLE);

            if(reachedBronze){
                bronzeTrophy.setVisibility(View.VISIBLE);
                showedBronzePopUp=true;
                reachedBronze=false;
                saveBronzeReward();
            }

            if(reachedSilver && counter>=50) {
                silverTrophy.setVisibility(View.VISIBLE);
                showedSilverPopUp=true;
                reachedSilver=false;
                saveSilverReward();
            }

            if(reachedGold && counter>=100) {
                goldTrophy.setVisibility(View.VISIBLE);
                showedGoldPopUp=true;
                reachedGold=false;
                saveGoldReward();
            }

            //start confetti
            container.stopDropping();
            container.setPer(10);
            container.setDropDuration(2400);
            container.setDuration(7200);
            container.setDropFrequency(500);
            container.startDropping();


        }
    });

0 个答案:

没有答案