Custom Dialog without title and border

后端 未结 8 879
终归单人心
终归单人心 2021-02-01 20:19

Based on the code here, http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog . I am successfully able to create a custom dialog with background and buttons ins

相关标签:
8条回答
  • 2021-02-01 21:09
    1. Make a class like this:

      public class CustomDialog extends Dialog {
          public AlertFinishiView(Context context) {
              super(context);
              requestWindowFeature(Window.FEATURE_NO_TITLE);
              setContentView(R.layout.dialog);
              getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
          }
      }
      
    2. make a xml in layut folder with this name dialog

      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:background="@android:color/transparent">
      
         <RelativeLayout 
            android:layout_width="220dp" 
            android:layout_height="140dp" 
            android:layout_centerHorizontal="true" 
            android:layout_centerVertical="true"            
            android:background="@drawable/bg_custom_dialog" >
      
            <Button android:id="@+id/button1" 
               android:layout_width="wrap_content" 
               android:layout_height="wrap_content" 
               android:layout_centerHorizontal="true" 
               android:layout_centerVertical="true" 
               android:text="Button" />
      
         </RelativeLayout>
      
      </RelativeLayout>
      
    3. add the image above in your drawable folder with name bg_custom_dialog.9.png

    bg_custom_dialog

    1. call in your activity:

      CustomDialog customDialog = new CustomDialog(this);
      customDialog.show();
      
    0 讨论(0)
  • 2021-02-01 21:10

    Use this, It works perfectly;

                 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before     
                 dialog.setContentView(R.layout.your_dialog_layout);
    
    0 讨论(0)
提交回复
热议问题