Android - change dialog button location

前端 未结 4 677
无人及你
无人及你 2021-01-13 14:09

Is it possible to change the location of the button on the dialog to the outside of the dialog itself? something like this (the red squares are buttons):

4条回答
  •  心在旅途
    2021-01-13 14:44

    Yes. All you have to do is create a custom dialog layout.

    In order to achieve that you would create a LinearLayout with Transparent BG color and inside it you can do whatever is it that you want.

    A quick example:

    
    
        
            ... your content here
        
    
        

    If you are using a builder to create your Dialog , you would go for this:

    LayoutInflater inflater = getActivity().getLayoutInflater();
    builder.setView(inflater.inflate(R.layout.your_dialog_layout, null))
    

    ...otherwise

    Dialog newDialog = new Dialog();
    newDialog.setContentView(R.layout.your_dialog_layout);
    

提交回复
热议问题