【发布时间】:2015-08-15 16:21:34
【问题描述】:
以下代码不会使 popupWindow 弹出,我试图使其工作的大多数事情都会使其崩溃,其中一些被注释,其余的只是没有成功。有线索吗?
// Popup the login
private void loginPopup(){
// Get the contents
RelativeLayout loginLayout = (RelativeLayout) findViewById(R.id.login_popup_layout);
EditText usernameTxt = (EditText) findViewById(R.id.login_popup_username);
EditText passwordTxt = (EditText) findViewById(R.id.login_popup_password);
Button registerBtn = (Button) findViewById(R.id.login_popup_register);
Button loginBtn = (Button) findViewById(R.id.login_popup_login);
Button GloginBtn = (Button) findViewById(R.id.login_popup_G);
Button FBloginBtn = (Button) findViewById(R.id.login_popup_FB);
//loginLayout.addView(usernameTxt);
// Popup the login menu
//View popupView = getLayoutInflater().inflate(R.layout.login_popup_layout, null);
PopupWindow loginPopup;
loginPopup = new PopupWindow(loginLayout, 100, 100);// The last true is to make it focusable
loginPopup.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
//loginPopup.setContentView(loginLayout);
// Center the popup and display it.
Display display = getWindowManager().getDefaultDisplay();
Point size=new Point();
display.getSize(size);
loginPopup.showAtLocation((RelativeLayout)findViewById(R.id.displayLayout), Gravity.NO_GRAVITY, 50,50 );//(size.x/2)-loginPopup.getWidth()/2 , (size.y/2)-loginPopup.getHeight()/2 );}
【问题讨论】:
-
new PopupWindow(view, 100, 100) :视图应该被膨胀(就像你在上面的行中所做的那样, getLayoutInflater()... )。您不能使用已经属于另一个布局的内容视图。
标签: java android android-studio android-popupwindow