0

I am working on a menu fragment which covers half of a screen when a button is clicked. After not being able to fulfil the requirements of the menu by using a fragment I decided to switch to a custom dialog. Using the custom dialog I was able to get the menu to behave as I wanted it to, however I am unable to get the animation effects (which worked perfectly on the previously used fragment) to appear when the custom dialog is shown or dismissed. The application works perfectly, but the animations do not appear. What is the issue here?

These are the two functions I use for my custom dialog:

private void initDialog() {

dialog = new Dialog(this, R.style.DialogCustomTheme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_menu);

// positioning
WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();
WMLP.x = -300;   //x position
WMLP.y = 100;   //y position
dialog.getWindow().setAttributes(WMLP);


dialog.getWindow().getAttributes().windowAnimations = R.anim.enter_from_left;
dialog.show();

initDialogViews();

}

private void initDialogViews() {

    dialog.findViewById(R.id.menuOption1).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Most Popular Items", Toast.LENGTH_LONG).show();
            dialog.getWindow().getAttributes().windowAnimations = R.anim.exit_to_left;
            dialog.dismiss();
        }
    });

    dialog.findViewById(R.id.menuOption2).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Top Rated Items", Toast.LENGTH_LONG).show();
            dialog.getWindow().getAttributes().windowAnimations = R.anim.exit_to_left;
            dialog.dismiss();
        }
    });

    dialog.findViewById(R.id.menuOption3).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Cheapest Items", Toast.LENGTH_LONG).show();
            dialog.getWindow().getAttributes().windowAnimations = R.anim.exit_to_left;
            dialog.dismiss();
        }
    });

    dialog.findViewById(R.id.menuOption4).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Free Items", Toast.LENGTH_LONG).show();
            dialog.getWindow().getAttributes().windowAnimations = R.anim.exit_to_left;
            dialog.dismiss();
        }
    });

    dialog.findViewById(R.id.menuLogIn).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Feature still not added!", Toast.LENGTH_LONG).show();
            dialog.getWindow().getAttributes().windowAnimations = R.anim.exit_to_left;
            dialog.dismiss();
        }
    });
}

enter_from_left.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
    android:fromXDelta="-100%"
    android:toXDelta="0%"
    android:fromYDelta="0%"
    android:toYDelta="0%"
    android:duration="2000"
    />

exit_to_left.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
<translate
    android:fromXDelta="0%"
    android:toXDelta="-100%"
    android:fromYDelta="0%"
    android:toYDelta="0%"
    android:duration="2000"
    />

Vasko Vasilev
  • 554
  • 1
  • 10
  • 25
  • Any reason why you’re setting the animations on a method that’s a getter (`getAttributes`)? – Edric Jul 10 '19 at 12:37
  • That's a piece of code I found for setting animations. From one of the answers to this question: https://stackoverflow.com/questions/4817014/animate-a-custom-dialog – Vasko Vasilev Jul 10 '19 at 12:55

0 Answers0