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"
/>