There is a ready application. When testing, it turned out that on the fifth androids, a dialogue in 2-3 cases out of 20 appears without animation with some twitching after appearing (i.e., the window appears without animation, extends a little bit literally on pixels and after that it can be seen how the background smoothly darkened). In other cases, the animation (tried and android.R.style.Animation_Dialog and its custom) is correctly worked out. On younger versions, everything is fine - this effect is not observed. It was tested on different mobile phones and emulators.

This is how the dialog from the Activity is called:

if (isActive) AuthDialog.makeDialog(context, this, null).show(this, getSupportFragmentManager()); 

Here is a helper for more convenient dialogue:

 public class AuthDialog { AuthDialogFragment rDialog; public AuthDialog(Context context, DialogResultInterface listener, JSONObject content) { try { Bundle arguments = new Bundle(); rDialog = new AuthDialogFragment(); rDialog.setResultListener(listener); arguments.putString(AuthDialogFragment.BUNDLE_CONTENT, content != null ? content.toString() : "{}"); rDialog.setArguments(arguments); rDialog.setStyle(DialogFragment.STYLE_NO_FRAME, 0); } catch (Exception e) { Logger.Exception(e); } } public static AuthDialog makeDialog(Context context) { return new AuthDialog(context, null, null); } public static AuthDialog makeDialog(Context context, DialogResultInterface listener) { return new AuthDialog(context, listener, null); } public static AuthDialog makeDialog(Context context, DialogResultInterface listener, JSONObject content) { return new AuthDialog(context, listener, content); } public void show(Activity activity, FragmentManager fragmentManager) { rDialog.show(fragmentManager, "AuthDialog"); } } 

This is actually the dialog class itself (tried both the standard DialogFragment and the support version):

 public class AuthDialogFragment extends DialogFragment implements View.OnClickListener { public static final String BUNDLE_CONTENT = "bundle_parameters"; private DialogResultInterface resultInterface; private JSONObject parameters = null; @Override public void setArguments(Bundle args) { super.setArguments(args); } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (getArguments() != null && getArguments().containsKey(BUNDLE_CONTENT)) { try { String strParam = getArguments().getString(BUNDLE_CONTENT); parameters = new JSONObject(strParam); } catch (Exception e) { Logger.Exception(e); } } else { parameters = new JSONObject(); } return super.onCreateDialog(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Logger.Log("Creating AuthDialog"); View currentView = inflater.inflate(R.layout.dialog_login, container, false); try { Window window = getDialog().getWindow(); window.setBackgroundDrawable(new ColorDrawable(0)); window.requestFeature(Window.FEATURE_NO_TITLE); WindowManager.LayoutParams windowParams = window.getAttributes(); windowParams.dimAmount = 0.20f; windowParams.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND; windowParams.windowAnimations = android.R.style.Animation_Dialog; window.setAttributes(windowParams); } catch (Exception e) { Logger.Exception(e); } currentView.findViewById(R.id.have_account).setOnClickListener(this); currentView.findViewById(R.id.new_user).setOnClickListener(this); currentView.findViewById(R.id.close_button).setOnClickListener(this); return currentView; } @SuppressWarnings("NullableProblems") @Override public void show(FragmentManager manager, String tag) { if (manager.findFragmentByTag(tag) == null) { super.show(manager, tag); } } @Override public void onClick(View lv) { switch (lv.getId()) { case R.id.have_account: Logger.Log("User selected LOGIN button..."); ...... dismiss(); break; case R.id.new_user: Logger.Log("User selected REGISTER button..."); ...... dismiss(); break; case R.id.close_button: Logger.Log("User selected CLOSE button"); dismiss(); break; default: Logger.Log("Unknown click from " + lv.toString()); break; } } public void setResultListener(DialogResultInterface listener) { if (listener != null) resultInterface = listener; } } 

Has anyone encountered this behavior? Is this my bug or is it a known Android 5.1 problem? How can this be corrected?

  • And you did not try to set the animation and other parameters of the window through the theme and not the code? - xkor
  • I tried the animation, and the other parameters are what? - Shutko Alexander
  • Others are all this code: Window window = getDialog().getWindow(); window.setBackgroundDrawable(new ColorDrawable(0)); window.requestFeature(Window.FEATURE_NO_TITLE); WindowManager.LayoutParams windowParams = window.getAttributes(); windowParams.dimAmount = 0.20f; windowParams.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND; windowParams.windowAnimations = android.R.style.Animation_Dialog; window.setAttributes(windowParams); Window window = getDialog().getWindow(); window.setBackgroundDrawable(new ColorDrawable(0)); window.requestFeature(Window.FEATURE_NO_TITLE); WindowManager.LayoutParams windowParams = window.getAttributes(); windowParams.dimAmount = 0.20f; windowParams.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND; windowParams.windowAnimations = android.R.style.Animation_Dialog; window.setAttributes(windowParams); . All this is possible and I think you need to ask in the subject. - xkor
  • I will try to check in the next couple of days - Shutko Alexander
  • No, porting this code to styles did not help. Absolutely nothing has changed. In the logs, too, nothing suspicious .... Disabling hardware acceleration in the manifest also did not help. - Shutko Alexander

0