如何关闭弹出窗口?

时间:2012-03-12 05:50:48

标签: java android popup

我有自定义弹出窗口(quickaction样式)的活动。有一些按钮可用于其他活动。我想在此弹出窗口中按下按钮(关于或电子邮件按钮)后关闭弹出窗口(现在再次出现弹出窗口时)。

public class FirstActivity extends Activity implements OnClickListener {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

               // some code

    Button quickButton = (Button) findViewById(R.id.button_quickaction);

    quickButton.setOnClickListener(this);

    final ActionItem about = new ActionItem();
    final ActionItem email = new ActionItem();

    quickButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            QuickAction qa = new QuickAction(v);

            qa.addActionItem(about);
            qa.addActionItem(email);
            qa.setAnimStyle(QuickAction.ANIM_GROW_FROM_RIGHT);

            qa.show();
        }
    });


    about.setTitle("About");
    about.setIcon(getResources().getDrawable(R.drawable.about));
    about.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //some code
        }
    });

    email.setTitle("Email");
    email.setIcon(getResources().getDrawable(R.drawable.email));
    email.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //some code
        }
    });

}

}

请帮助。


加了:

我需要这样的东西:

about.setTitle("About");
    about.setIcon(getResources().getDrawable(R.drawable.about));
    about.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            qa.dismiss();
        }
    });

qa无法解决。即使我将final添加到QuickAction qa = new QuickAction(v);

1 个答案:

答案 0 :(得分:2)

在按钮的onClick方法上尝试finish()

<强>更新

QuickAction qa;
quickButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            qa = new QuickAction(v);

            qa.addActionItem(about);
            qa.addActionItem(email);
            qa.setAnimStyle(QuickAction.ANIM_GROW_FROM_RIGHT);

            qa.show();
        }
    });


    about.setTitle("About");
    about.setIcon(getResources().getDrawable(R.drawable.about));
    about.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if(qa.isShowing())
               qa.dismiss();
            //some code
        }
    });

    email.setTitle("Email");
    email.setIcon(getResources().getDrawable(R.drawable.email));
    email.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if(qa.isShowing())
               qa.dismiss();
            //some code
        }
    });

您也可以将private QuickAction qa;放在您的活动中。