为什么android java popupWIndow不';你不来吗?
下面的代码并没有使popupWindow弹出窗口,我试图使它工作的大多数东西使它崩溃,其中一些是注释的,其余的就是不起作用。有线索吗为什么android java popupWIndow不';你不来吗?,java,android,android-studio,android-popupwindow,Java,Android,Android Studio,Android Popupwindow,下面的代码并没有使popupWindow弹出窗口,我试图使它工作的大多数东西使它崩溃,其中一些是注释的,其余的就是不起作用。有线索吗 // Popup the login private void loginPopup(){ // Get the contents RelativeLayout loginLayout = (RelativeLayout) findViewById(R.id.login_popup_layout); EditText usernameTx
// 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 );}
我用错了,我的PopupWindow不是一个从视图中弹出的窗口,我想的是一个完整的窗口,它覆盖了屏幕的很大一部分,有一个单独的布局,有自己的类等等。。。 最后,我做了一个新的活动,具有自定义的宽度和高度,并使活动未覆盖的黑色区域透明。看来这是正确的实施方式。 在所附的代码中,窗口没有弹出,因为我没有将其充气。新建PopupWindow(视图,100100):视图应该充气(就像上面一行中的getLayoutInflater()…)。不能使用已属于其他版面的内容视图。