custom dialog with close button

前端 未结 8 1752
天涯浪人
天涯浪人 2020-12-01 11:35

I want to create a custom dialog with the layout as shown in the picture. \"enter The cross/cl

8条回答
  •  情书的邮戳
    2020-12-01 12:14

    enter image description here

    ![anybody can try above all but u will be facing problem background color problem
    
    i have done very simple way 
    
    
    
      
        
    
    
    
                
    
                    
    
                        
    
                        
                        
    
                        
                    
    
                    
    
                    
    
                        
    
                        
    
                        
                        
    
                        
    
                        
    the dialog must be like that
    
       private void ChildSectionView() {
    
                final Dialog dialog = new Dialog(NewObservationActivity.this);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.custom_dialog_obs_children);
                // Grab the window of the dialog, and change the width
                dialog.getWindow().setBackgroundDrawable(
                        new ColorDrawable(android.graphics.Color.TRANSPARENT));
                WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                Window window = dialog.getWindow();
                lp.copyFrom(window.getAttributes());
    
                Display display = getWindowManager().getDefaultDisplay();
                Point size = new Point();
                display.getSize(size);
                lp.width = size.x;
                lp.height = size.y;
                // This makes the dialog take up the full width
                window.setAttributes(lp);
    
                gridview = (GridView) dialog.findViewById(R.id.gridview_observation);
    
                ImageView icon_close = (ImageView) dialog.findViewById(R.id.icon_close);
                child_count = (TextView) dialog
                        .findViewById(R.id.text_child_count_dialog);
    
                child_count.setText("Selected " + intList.size() + " more children");
                SearchView searchview = (SearchView) dialog
                        .findViewById(R.id.search_children);
    
                icon_close.setOnClickListener(new OnClickListener() {
    
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
    
                searchview.setOnQueryTextListener(new OnQueryTextListener() {
    
                    @Override
                    public boolean onQueryTextSubmit(String arg0) {
                        // TODO Auto-generated method stub
                        return false;
                    }
    
                    @Override
                    public boolean onQueryTextChange(String string) {
                        filItemAdapter("N", string);
                        return false;
                    }
                });
    
                filItemAdapter("", "");
    
                dialog.show();
            }
    

    Note :-------

    the relative layout background should be transparent
    and dialog background also
    dialog.getWindow().setBackgroundDrawable(
    new ColorDrawable(android.graphics.Color.TRANSPARENT));][2]
    

提交回复
热议问题