relativelayout中的Textview和按钮在android oreo和pie中不可见,但在其他android版本中完全可见

病毒王

relativelayout中的Textview和button在android oreo和pie中不可见,而在其他android版本中则完全可见。

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);
                            }
                        }
                    }
                }
            });
        }

供您参考,我附上了xml代码的屏幕截图: 在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

第一张截图显示了oreo以下和oreo上方的正常屏幕 在此处输入图片说明

当我单击oreo下面的promocode复选框时,第二张屏幕截图完美显示: 在此处输入图片说明

当我单击oreo和pie中的promocode复选框时,第三张屏幕截图显示不完美 在此处输入图片说明

纳西姆·阿什拉夫(MD Naseem Ashraf)

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;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章