我正在为android编写一个程序,我想使用一个带有两个按钮的弹出菜单当我点击它们时,它们会打开另一个活动。我该怎么做?
答案 0 :(得分:0)
查看如下:
View view = getLayoutInflater().inflate(R.layout.SOME_LAYOUT, false);
Button button1 = (Button) view.findViewById(R.id.BUTTON1_ID);
button1.setOnClickListener(...start new Activity);
Button button2 = (Button) view.findViewById(R.id.BUTTON2_ID);
button2.setOnClickListener(...start new Activity);
将此视图设置为内容:
PopupWindow popup = new PopupWindow(getContext());
popup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
popup.setContentView(view);
popup.setWidth(view.getWidth());
popup.setHeight(view.getHeight());
popup.setFocusable(true);
popup.showAsDropDown(PARENT_VIEW);
视图是膨胀的布局,它有两个带有设置点击监听器的按钮。父视图将在单击时显示此弹出窗口。
祝你好运!