Android 复制/粘贴上下文菜单在对话框中使用时有幽灵背景

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

我有一个简单的对话框,其中包含一个注释字段,当我长按一个项目时,就会发生这种情况(我附加不同的状态,以更好地理解问题)

Menu when selecting a text

Menu when selecting a text and after tapping on the 3 dots

Menu when selecting a blank space

现在,这就是我已经尝试过的

  • 自定义布局更改。我所做的是将普通的 MaterialAlertDialogBuilder 与 setview 方法一起使用。视图本身只是一个文本字段,但我也尝试将其封装在框架布局中,或者放置一个带有可选文本的简单文本视图。没有变化。这是 kotlin 部分

         // Native dialog
         MaterialAlertDialogBuilder(act)
             .setView(dialogNotesBinding.root)
             .setTitle(notesTitle)
             .setIcon(R.drawable.ic_note_24dp)
             .setPositiveButton(resources.getString(android.R.string.ok)) { dialog, _ ->
                 ...
             }
             .setNegativeButton(resources.getString(android.R.string.cancel)) { dialog, _ ->
                 dialog.dismiss()
             }
             .show()
    

这是自定义布局:

  <?xml version="1.0" encoding="utf-8"?>
  <com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/favoritesNotesLayout"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ... >

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/favoritesNotes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ... />

</com.google.android.material.textfield.TextInputLayout>
  • 更改材质组件版本:我尝试了 1.12.0 和 1.13.0 alpha,没有变化

我没主意了。

android dialog popup material-design contextmenu
1个回答
0
投票

长话短说:我有一种对话风格,类似于这个问题的答案中使用的风格 但是,设置对话框的属性 android:background 会导致上下文菜单上出现此错误。解决方案是使用 android:dialogPreferenceStyle 而不是 materialAlertDialogTheme 对首选项对话框进行主题化,解决方案的工作方式相同,但副作用较小。

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