Set custom layout in popup window in android

前端 未结 6 1851
别那么骄傲
别那么骄傲 2020-12-05 23:42

I have a problem with popup window. I want to create popup window with my own layout. This is code:

public class PopupWindowView extends PopupWindow{

    P         


        
6条回答
  •  日久生厌
    2020-12-06 00:36

    You can use following code. you need to use PopupWindow for this.

    PopupWindow mpopup;   
    

    then you need to inflate your view.

        View popUpView = getLayoutInflater().inflate(R.layout.activity_login,
                null); // inflating popup layout
        mpopup = new PopupWindow(popUpView, LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT, true); // Creation of popup
        mpopup.setAnimationStyle(android.R.style.Animation_Dialog);
        mpopup.showAtLocation(popUpView, Gravity.CENTER, 0, 0); // Displaying popup  
    

    if your layout have some item then you need bind that item with your view.

        TextView some = (TextView) popUpView.findViewById(R.id.some);       
        Button btnCancel = (Button) popUpView.findViewById(R.id.btnCancel);  
    

    onClickListener of your popup windows item.

        btnCancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mpopup.dismiss();
            }
        });   
    

    You can dismiss your PopupWindow using mpopup.dismiss();

提交回复
热议问题