【问题标题】:Why does this android java popupWIndow doesn't show up?为什么这个 android java popupWIdow 不显示?
【发布时间】: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


【解决方案1】:

我用错了,我对 PopupWindow 的想法不是一个从视图中弹出的窗口,我在想一个覆盖屏幕很大一部分的整个窗口,它有一个单独的布局和它自己的类等等…… 最后,我做了一个新的活动,具有自定义的宽度和高度,并使未被活动覆盖的黑色区域透明。看来这是正确的实现。 在附加的代码中,没有弹出窗口,因为我没有给它充气。

【讨论】:

    猜你喜欢
    • 2023-03-14
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 2018-04-19
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多