Search code examples
androidandroid-8.0-oreoandroid-9.0-pie

Textview and button inside the relativelayout not get visible in android oreo and pie but visible in other android version perfectly


Textview and button inside the relativelayout not get visible in android oreo and pie but visible in other android version perfectly.

if (mPromocodeCheckBox != null) {
            mPromocodeCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (inputMethodManager == null)
                        inputMethodManager = (InputMethodManager) ALTCommonUtils.currentActivity.getSystemService(Context.INPUT_METHOD_SERVICE);

                    if (mPromocodeLayout != null) {
                        if (isChecked) {
                            mPromocodeLayout.setVisibility(View.VISIBLE);
                            if (inputMethodManager != null && mPromocodeEditText != null) {
                                mPromocodeEditText.requestFocus();
                                inputMethodManager.showSoftInput(mPromocodeEditText, InputMethodManager.SHOW_IMPLICIT);
                            }
                            if (mPromocodeApplyButton != null)
                                mPromocodeApplyButton.setVisibility(View.VISIBLE);

                            if (mPromocodeEditText != null)
                                mPromocodeEditText.setEnabled(true);
                        } else {
                            mPromocodeLayout.setVisibility(View.GONE);
                            HandleViewsUtils.TextView_SetText(mPromocodeMsg, "");

                            if (inputMethodManager != null && mPromocodeEditText != null) {
                                HandleViewsUtils.EditText_SetText(mPromocodeEditText, "");
                                inputMethodManager.hideSoftInputFromWindow(mPromocodeEditText.getApplicationWindowToken(), 0);
                            }
                        }
                    }
                }
            });
        }

For you reference i has attached the screenshot of xml code : enter image description here

enter image description here

enter image description here

1st screenshot shows the normal screen for both below oreo and above oreo enter image description here

2nd screenshot shows perfectly when i click promocode checkbox in below oreo : enter image description here

3rd screenshot shows imperfect when i click promocode checkbox in oreo and pie enter image description here


Solution

  • Your xml screenshots were painful to read but, I just realized you're using fill_parent instead of match_parent. FILL_PARENT is deprecated in API 8 afterwards; Google Developer Documentation Source. Why you should use Match Parent.

    Maybe it's time you moved towards the more recently introduced methods, design patterns and libraries. Start using Constraint Layout instead of Relative Layout. Benefits of Constraint Layout and its introduction in Android Studio 2.2 onwards. Stop using Relative Layouts and use them only when very necessary. Google I/O Talk of 2018 on Layouts, Link. You don't know when Google will decide to deprecate it and then you'd have projects that will stop working.

    Another thing to keep in mind is the new Support Library AndroidX, to which you should start migrating your older projects. AndroidX will be the new singular support library for future and all that weird number based support libraries will be discontinued.

    The last most important thing is you should start developing for Android API 28+ which will be enforced by Google from this year onwards; Google Developers Youtube Video. So, start migrating to current APIs and support library.

    Hope this helps.

    Addendum Make sure of Android Studio's alerts on your codebase regarding deprecation. More links here;