双击不会在对讲模式下单击父视图 [英] Double tap doesn't click the parent view in talkback mode

查看:100
本文介绍了双击不会在对讲模式下单击父视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下xml文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/linear_layout1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:focusable="true"
        android:layout_margin="10dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:text="first text"
            android:layout_margin="10dp"/>

        <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="second text"
            android:layout_margin="10dp"/>

    </LinearLayout>

</LinearLayout>

我为LinearLayout和TextView设置了一个单击侦听器。

I have set a click listener for LinearLayout and TextView.

TextView textView1 = (TextView) findViewById(R.id.text1);
LinearLayout linearLayout = findViewById(R.id.linear_layout1);
linearLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(v.getContext(), "Linear layout clicked", Toast.LENGTH_SHORT).show();
                }
            });

textView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "text view clicked", Toast.LENGTH_SHORT).show();
            }
        });

我使LinearLayout具有可聚焦性,因此在对讲模式下,它可以得到可访问性焦点。现在,当我双击它时,将调用文本视图的单击事件,而不是线性布局。

I have made the LinearLayout focusable so that in talkback mode, it can get the accessibility focus. Now when I double tap on it, click event of text view is called instead of linear layout.

我如何使其改为线性布局的单击侦听器?

How can I make it call the click listener of linear layout instead?

推荐答案

我遇到了同样的问题,并通过创建新的View(解决方案)解决了这个问题,该View扩展了LinearLayout,在此View中,我已覆盖 onInterceptTouchEvent()方法。在此方法中,检查是否打开了辅助功能,以及是否选择了ViewGroup(LinearLayout)。如果是这样,则返回true并拦截此事件。

I had the same problem and I solved it by creating new View, which was extending LinearLayout and in this View I have overriden onInterceptTouchEvent() method. In this method is checked whether Accessibility is turned on and if the ViewGroup (LinearLayout) is selected. If so, return true and intercept this event.

public class AccessibleLinearLayout extends LinearLayout {

    public AccessibleLinearLayout(Context context) {
        super(context);
    }

    public AccessibleLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AccessibleLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled() && isAccessibilityFocused()) {
            return true;
        }
        return super.onInterceptTouchEvent(ev);
    }
}

我不确定您是否需要检查(((AccessibilityManager)getContext()。getSystemService(Context.ACCESSIBILITY_SERVICE))。isEnabled()当您检查 isAccessibilityFocused()

I'm not sure if you need to check ((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled() when you check if isAccessibilityFocused()

这篇关于双击不会在对讲模式下单击父视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆