0
我正在寫一個程序爲Android,我想使用有當我點擊他們每個人的兩個按鈕,彈出菜單,他們打開另一個activity.How我能做到這一點?如何使用帶按鈕的彈出式菜單?
我正在寫一個程序爲Android,我想使用有當我點擊他們每個人的兩個按鈕,彈出菜單,他們打開另一個activity.How我能做到這一點?如何使用帶按鈕的彈出式菜單?
查看看起來是這樣的:
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);
View是虛增佈局至極擁有一套點擊監聽兩個按鈕。父視圖是在點擊時顯示此彈出窗口。
祝你好運!