How to make custom dialog with rounded corners in android

前端 未结 16 934
半阙折子戏
半阙折子戏 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:34

    Here is the complete solution if you want to control the corner radius of the dialog and preserve elevation shadow

    Dialog:

    class OptionsDialog: DialogFragment() {
    
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle?): View {
        dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        return inflater.inflate(R.layout.dialog_options, container)
    }
    
    }
    

    dialog_options.xml layout:

    
    
    
    
        
        
    
    
    
    

    The key is to wrap the CardView with another ViewGroup (here FrameLayout) and set margins to create space for the elevation shadow.

提交回复
热议问题