我在android中创建了一个按钮,当点击它时会显示弹出窗口..但是代码不会像那样工作..它没有错误,但不显示弹出窗口...请helpme。 。这里是我的代码 公共类MainActivity扩展活动{在android中弹出窗口弹出窗口
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final RelativeLayout objrl = (RelativeLayout) findViewById(R.id.myrl);
final Button objButton = (Button) findViewById(R.id.mybutton);
objButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupWindow objPopupWindow = new PopupWindow(objrl, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
objPopupWindow.setAnimationStyle(R.drawable.background2);
objPopupWindow.showAtLocation(objButton, Gravity.CENTER_HORIZONTAL, 10, 10);
}
});
}
入住这Andwer http://stackoverflow.com/a/18867300/1160282 – SilentKiller 2014-08-30 11:21:07
哦.. !!我不明白你为什么挑剔物体......?解释 – FaKe 2014-08-30 11:21:19
我只是格式化了你的代码。 – SilentKiller 2014-08-30 11:22:14