【问题标题】:Xamarin forms - How to detect whether the device is touch device or not?Xamarin forms - 如何检测设备是否是触摸设备?
【发布时间】:2016-12-07 05:07:23
【问题描述】:

我正在使用 xamarin 表单跨平台 PCL 项目开发应用程序。我需要知道我是否可以检测到设备是否是触摸设备?有可能检测到吗?

【问题讨论】:

  • 您打算制作电视应用吗?这就是你问的原因吗?如果是这样,您可以从主要活动中的 android 项目中知道这一点。
  • @BraveHeart 怎么样?你有示例代码吗
  • 我已经给你发了样品,这能回答你的问题吗?
  • 是的,它有帮助。谢谢@BraveHeart

标签: c# xamarin xamarin.forms portable-class-library


【解决方案1】:

XF 不知道设备是否为触摸设备,但您可以使用Device.Idiom 检测您正在运行的设备类型。如果您收到TargetIdiom.Desktop,您就会知道,除了可能的触摸屏之外,用户可能还有键盘和鼠标。

【讨论】:

    【解决方案2】:

    我想您是在要求它制作一个电视应用程序。 不幸的是,此时 Xamarin.Forms 找不到,但是您可以在主 Activity 中执行此操作,如下所示

     var uiModeManager = (UiModeManager) GetSystemService(UiModeService);
    if (uiModeManager.CurrentModeType == UiMode.TypeTelevision)
    {
         _isTv = true;
    
    }
    else
    {
    _isTv = false;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-12
      相关资源
      最近更新 更多