Change DialogFragment enter/exit transition at just before dismissing

后端 未结 5 1859
别那么骄傲
别那么骄傲 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:43

    I think the best approach is to call the different animations on Button click. Hence you would have something similar to the below:

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Button OkButton = (Button) findViewById(R.id.btnOk);
            Button CancelButton = (Button) findViewById(R.id.btnCancel);
    
            OkButton.setOnClickListener(new OnClickListener() {
    
                @Override    
                public void onClick(View view) {
                        getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;    
                }
            });
            return true;
    
            CancelButton.setOnClickListener(new OnClickListener() {
    
                @Override    
                public void onClick(View view) {
                    getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogAnimation2;    
                }
            });
            return true;
        }
    

    If I were you, I would also use correct naming conventions for future reference. For example setting DialogAnimation to OkAnimation and DialogAnimation2 to CancelAnimation.

    Home this helps :)

提交回复
热议问题