gpt4 book ai didi

java - PopupWindow 与 ActionBar 重叠

转载 作者:行者123 更新时间:2023-12-02 02:08:08 37 4
gpt4 key购买 nike

我使用 PopupWindow 通过 showAsDropDown(anchor) 显示验证错误。验证字段通过按保存按钮进行验证,因此如果 anchor 位于操作栏下方,则其弹出窗口会与操作栏重叠。我该如何解决这个问题?

Example

 protected void showPopup(View anchorPlace) {
popupContainer.removeAllViews();
popupContainer.addView(recyclerErrors);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
popupContainer.setElevation(0);
anchorPlace.setElevation(0);
popup.setElevation(0);
}
recyclerErrors.setOnClickListener(v -> dismissPopup());
popup.setContentView(popupContainer);
if (anchorPlace != null) {
popup.setWidth(anchorPlace.getWidth());
}
popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setOutsideTouchable(true);
popup.setFocusable(false);
popup.setTouchable(true);
popup.setBackgroundDrawable(null);

if (anchorPlace != null) {
PopupWindowCompat.showAsDropDown(popup, anchorPlace, 0, 0, Gravity.BOTTOM);
}

if (popup.isAboveAnchor()) {
popup.dismiss();
}
}

弹出验证错误 XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
app:srcCompat="@drawable/warning_triangle" />

<TextView
android:id="@+id/error_field_error_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/warning_bcg"
android:drawableStart="@drawable/ic_warning"
android:drawablePadding="@dimen/settings_error_body_padding_top_bottom"
android:gravity="center_vertical"
android:paddingStart="@dimen/settings_error_body_padding_start_end"
android:paddingTop="@dimen/settings_error_body_padding_top_bottom"
android:paddingEnd="@dimen/settings_error_body_padding_start_end"
android:paddingBottom="@dimen/settings_error_body_padding_top_bottom"
android:textColor="@android:color/white"
android:textSize="@dimen/settings_error_text_size"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/></LinearLayout>

最佳答案

尝试popup.setAttachedInDecor(true)

This will attach the popup window to the decor frame of the parent window to avoid overlaping with screen decorations like the navigation bar.

您也可以尝试使用popup.setOverlapAnchor(false)

Sets whether the popup window should overlap its anchor view when displayed as a drop-down.

希望有帮助。

关于java - PopupWindow 与 ActionBar 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59252345/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com