Search code examples
androidandroid-fragmentsandroid-intentandroid-developer-api

How fix dialog deformations when build to a lower OS version?


I am running my android app in my android phone which is OS 8.1 Oreo and it seems no problem with the dialogue, but when i install/build to other phone which is android lollipop the dialogue deform to its original size.

See image below.

Please click for the image (Error design deform)

Source code on dialogue

 final Dialog dialog = new Dialog(context);
        dialog.setContentView(R.layout.dialogue_dash_date_picker);

        final Spinner spinner = dialog.findViewById(R.id.typeViewSpinner);
        Button btnDismiss = dialog.findViewById(R.id.btnOK);
        String viewType = ViewTypeSingleton.getInstance().getTypeview();
        if (viewType.equals(""))
            spinner.setSelection(0);
        else if (viewType.equals("Day"))
            spinner.setSelection(1);
        else if (viewType.equals("Week"))
            spinner.setSelection(2);
        else if (viewType.equals("Month"))
            spinner.setSelection(3);
        else if (viewType.equals("Year"))
            spinner.setSelection(4);
        else if (viewType.equals("All"))
            spinner.setSelection(5);

        btnDismiss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
                String choosen = spinner.getSelectedItem().toString();
                ViewTypeSingleton.getInstance().setTypeview(choosen);
                message.success(""+choosen,context);
                fragmentRedirection(new fragment_main());
            }
        });
        dialog.create();
        dialog.show();

Please help me fix this one.

Thanks


Solution

  • Add this style into your style.xml

    <style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    
        <item name="android:windowBackground">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">false</item>
    
    </style>
    

    And Create your dialog like this

     final Dialog dialog = new Dialog(context, R.style.MyDialogTheme);