Change DialogFragment enter/exit transition at just before dismissing

后端 未结 5 1867
别那么骄傲
别那么骄傲 2020-12-13 01:48

I have a DialogFragment and I set animation for enter/exit in the onActivityCreated method as below:

  @Override
    public void on         


        
5条回答
  •  渐次进展
    2020-12-13 02:24

    You should set a theme for your base dialog

    let say :-

    public class CustomDialogFragment extends DialogFragment implements OnEditorActionListener
    {
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) 
        {
            return super.onCreateView(inflater, container, savedInstanceState);
        }
    
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) 
        {
            // Set a theme on the dialog builder constructor!
            AlertDialog.Builder builder = 
                new AlertDialog.Builder( getActivity(), R.style.MyCustomTheme );
    
            builder  
            .setTitle( "Your title" )
            .setMessage( "Your message" )
            .setPositiveButton( "OK" , new DialogInterface.OnClickListener() 
                {      
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                  dismiss();                  
                }
            });
            return builder.create();
        }
    }
    

    Then you just need to define the theme that will include your desired animation. In styles.xml add your custom theme:

    
    
     
    

    refer this

提交回复
热议问题