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

问题描述 投票:1回答:1

relativelayout中的Textview和按钮在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代码的屏幕截图:enter image description here

enter image description here

enter image description here

第1个屏幕截图显示了oreo和oreo enter image description here以下的正常屏幕

当我点击下面的oreo:enter image description here中的promocode复选框时,第二个屏幕截图显示完美

当我点击oreo和pie enter image description here中的promocode复选框时,第3个屏幕截图显示不完美

android android-8.0-oreo android-9.0-pie
1个回答
1
投票

你的xml截图很难读,但我刚刚意识到你正在使用fill_parent而不是match_parent。之后,API 8中不推荐使用FILL_PARENT; Google Developer Documentation SourceWhy you should use Match Parent

也许是时候你转向最近推出的方法,设计模式和库。开始使用约束布局而不是相对布局。 Benefits of Constraint Layout及其introduction in Android Studio 2.2开始。停止使用相对布局并仅在非常必要时使用它们。关于布局的2018年Google I / O谈话,Link。您不知道Google何时会决定弃用它,然后您将有停止工作的项目。

另外要记住的是新的支持库AndroidX,您应该开始迁移旧项目。 AndroidX将成为未来的新奇异支持库,所有基于奇数的支持库都将停止使用。

最重要的是你应该开始开发Android API 28+,这将从今年开始由Google强制执行;谷歌开发者Youtube Video。因此,开始迁移到当前的API和支持库。

希望这可以帮助。

附录确保您的代码库上的Android Studio警告有关弃用的信息。这里有更多链接;

© www.soinside.com 2019 - 2024. All rights reserved.