How to make custom dialog with rounded corners in android

前端 未结 16 882
半阙折子戏
半阙折子戏 2020-11-28 02:15

What I am trying to do: I am trying to make a custom dialog in android With rounded corners.

What is happening: I am able to make c

16条回答
  •  眼角桃花
    2020-11-28 02:42

    You need to do the following:

    • Create a background with rounded corners for the Dialog's background:

      
      
      
          
      
          
      
      
      
    • Now in your Dialog's XML file in the root layout use that background with required margin:

      android:layout_marginLeft="20dip"
      android:layout_marginRight="20dip"
      android:background="@drawable/dialog_background"
      
    • finally in the java part you need to do this:

      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
      dialog.setContentView(layoutResId);
      View v = getWindow().getDecorView();
      v.setBackgroundResource(android.R.color.transparent);
      

    This works perfectly for me.

提交回复
热议问题