//创建layoutinflator尝试{
LayoutInflater inflator = LayoutInflater.from(this);
//创建视图
final View menuview = inflater.inflate(R.layout.menu,
(ViewGroup) findViewById(R.layout.dictionarylist));
Button Menu = (Button) findViewById(R.id.Menu);
Menu.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
final PopupWindow pw = new PopupWindow(menuview);//initialize popupwindow
pw.showAtLocation(v, Gravity.CENTER, 0, 0);
pw.update(0, 0, 200, 250);
pw.setOutsideTouchable(false);//set outside touch to false
//的onclick侦听内popupwindow按钮
Button b1 = (Button) menuview.findViewById(R.id.btnClose);
b1.setOnClickListener(new OnClickListener() {
// @Override
public void onClick(View v) {
pw.dismiss();
}
});
Button b2 = (Button) menuview.findViewById(R.id.btnQuiz);
b2.setOnClickListener(new OnClickListener() {
// @Override
public void onClick(View v) {
}
});
Button b3 = (Button) menuview.findViewById(R.id.btnTopic);
b3.setOnClickListener(new OnClickListener() {
// @Override
public void onClick(View v) {
InitialTask2 Task1 = new InitialTask2();
Task1.execute();
}
});
Button b4 = (Button) menuview
.findViewById(R.id.btnDictionarylist);
b4.setOnClickListener(new OnClickListener() {
// @Override
public void onClick(View v) {
try{
if(getApplication() != null){
pw.dismiss();
}
else{
Intent i = new Intent();
i.setClass(getBaseContext(), Dictionarylist.class);
startActivity(i);
}
}
catch(Exception x){
x.getMessage();
}
}
});
}
});
} catch (Exception e) {
e.getMessage();
}
}
外面点击弹出窗口不起作用pw.setOutsideTouchable(false);
。 当弹出窗口外单击它执行放置在弹出窗口即父窗口的后面行动。