【发布时间】:2020-12-06 23:56:49
【问题描述】:
目前我观察到“通过”片段显示工具提示的奇怪行为,但我不知道如何摆脱它。任何想法或提示将不胜感激!
我有一个ImageButton 和一些contentDescription:
<androidx.appcompat.widget.AppCompatImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="Content description"
android:src="@drawable/ic_image"
/>
这样做是为了让用户在将触控笔/S-Pen 或鼠标指针悬停在图像上时看到帮助文本。这是一种期望的行为:
当AlertDialog 显示在活动上方时,不会显示任何工具提示。这也是一种预期行为:
但是,当片段显示在ImageButton 上时,总是会显示工具提示。这是一个不受欢迎的行为,也是这个问题的一大奥秘。该片段具有半透明的绿色背景:
片段布局中使用了一个简单的FrameLayout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#B94EC14A"
/>
用户可以点击片段。
如果添加这些行,可以摆脱“点击”行为,但不能摆脱“悬停”:
layout1.setClickable(true);
layout1.setFocusable(true);
layout1.setOnTouchListener((v, event) -> true);
layout1.setOnHoverListener((v, event) -> true);
layout1.setOnGenericMotionListener((v, event) -> true);
这里似乎使用了其他类型的事件。
- 哪种事件用于通过视图翻译“悬停”事件?
- 如何防止出现此工具提示? (需要与 AlertDialog 类似的行为)
【问题讨论】:
标签: android tooltip android-imagebutton onhover stylus-pen