【问题标题】:disabling multitouch across the appwide in android xamarin在android xamarin中禁用整个应用程序的多点触控
【发布时间】:2016-05-13 09:17:27
【问题描述】:

Xamarin 论坛问题链接: https://forums.xamarin.com/discussion/60321/disabling-multitouch-across-the-appwide-in-android-xamarin#latest

有没有办法在 Xamarin Android 中禁用多点触控应用程序。 我目前有一个 PCL 项目。使用 Xamarin 表单 UI 实现的共享代码。

我只是想阻止用户在 Android 中点击超过 1 个按钮。

我们所有的按钮都是基于 ICommand 并从 viewModel 调用的。它们都是异步任务(我们想让它们非阻塞并在后台线程中运行)。 --> 这种方法在 iOS 中运行良好,只是想在 Android 应用范围内禁用它。

我在 MainActivity.cs 中尝试了以下操作

public override bool OnTouchEvent(MotionEvent e)
{
    if(e.PointerCount > 1)
    {

     return false;
    }
    else
    {
        return base.OnTouchEvent(e);
    }

}

但这并没有什么不同。任何帮助将不胜感激

public override void OnUserInteraction()
    {
        base.OnUserInteraction();
    }

有效,但没有给我触摸事件的数量

【问题讨论】:

    标签: android xamarin


    【解决方案1】:

    应用禁用多点触控的应用程序主题 (derived from this answer)。

    Resources/Values 下添加一个名为 Styles.xml 的文件,其中包含以下代码:

    <?xml version="1.0" encoding="UTF-8" ?>
    <resources>
        <style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">    
            <item name="android:windowEnableSplitTouch">false</item>
            <item name="android:splitMotionEvents">false</item>
        </style>
    </resources>
    

    android:windowEnableSplitTouch 表示是否可以在其他也支持拆分触摸的窗口之间拆分触摸。

    android:splitMotionEvents 指示 ViewGroup 在触摸事件调度期间是否应将 MotionEvents 拆分为单独的子视图。

    在应用程序主题级别应用这些将强制对应用程序中的所有视图进行单点触控。

    然后在您的应用程序清单中将样式应用于application 上的android:theme 属性:

    清单示例:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
            android:versionCode="1" 
            android:versionName="1.0" 
            package="com.companyname.testapp">
        <uses-sdk android:minSdkVersion="11" />
        <application 
            android:allowBackup="true" 
            android:icon="@mipmap/icon" 
            android:label="@string/app_name" 
            android:theme="@style/MyAppTheme">
        </application>
    </manifest>
    

    这将禁用整个应用程序的多点触控。

    【讨论】:

    • @matthewdev。感谢您的回答。我已经想出了解决这个问题的办法。这是一种不同的方法。这里是:1)当我同时单击 2 个按钮时(页面 pushasync() 都被触发) 2)但是 Device.BeginInvokeOnMainthread 一次只呈现一个页面(本质上是连续的)。因此,我在两次按下按钮期间都将标志设置为 false,并且仅在任一页面的 onAppearing 期间将其设置为 true。为了更好地衡量,我使用了 Device.StartTimer(new Timespan(0,0,60)。在一分钟后将标志设置为 true。这似乎已经停止了多个按钮点击上的多页推送
    • 我的解决方案发布在 Xamarin 论坛上的这个线程上:forums.xamarin.com/discussion/comment/178741#Comment_178741
    • @wsr007 很高兴看到您找到了解决方案!
    猜你喜欢
    • 2011-11-03
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 2019-01-13
    • 1970-01-01
    • 1970-01-01
    • 2011-10-24
    • 1970-01-01
    相关资源
    最近更新 更多