如果在Activity中的onCreate()方法中使用setDefaultKeyMode()可以做到在当前activity中打开拨号器、执行快捷键、启动本地搜索、启动全局搜索。

这个启动啥,要看setDefaultKeyMode中传了啥参数,不同的参数见下:

/**     * Use with {@link #setDefaultKeyMode} to turn off default handling of     * keys.     *      * @see #setDefaultKeyMode*/static public final int DEFAULT_KEYS_DISABLE = 0; //如果设为这个,则在activity中按键的不做响应    /**     * Use with {@link #setDefaultKeyMode} to launch the dialer during default     * key handling.     *      * @see #setDefaultKeyMode*/static public final int DEFAULT_KEYS_DIALER = 1; //如果设为这个,则在activity中按键会打开拨号器

/**     * Use with {@link #setDefaultKeyMode} to execute a menu shortcut in     * default key handling.     *      * <p>That is, the user does not need to hold down the menu key to execute menu shortcuts.     *      * @see #setDefaultKeyMode*/static public final int DEFAULT_KEYS_SHORTCUT = 2; //如果设为这个,则在activity中按键会启动快键键    /**     * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes     * will start an application-defined search.  (If the application or activity does not     * actually define a search, the the keys will be ignored.)     *      * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details.     *      * @see #setDefaultKeyMode*/static public final int DEFAULT_KEYS_SEARCH_LOCAL = 3; //如果设为这个,则在activity中按键会打开本地搜索

/**     * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes     * will start a global search (typically web search, but some platforms may define alternate     * methods for global search)     *      * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details.     *      * @see #setDefaultKeyMode*/static public final int DEFAULT_KEYS_SEARCH_GLOBAL = 4; //如果设为这个,则在activity中按键会打开全局搜索

Select the default key handling for this activity. This controls what will happen to key events that are not otherwise handled(没有操纵的按键,在局部搜索是,我没设置之前,点击数字键是没有反应的,但是我点击以后,数字键就会自动搜索对应的点击的数字按键). The default mode (DEFAULT_KEYS_DISABLE) will simply drop them on the floor. Other modes allow you to launch the dialer (DEFAULT_KEYS_DIALER), execute a shortcut in your options menu without requiring the menu key be held down (DEFAULT_KEYS_SHORTCUT), or launch a search (DEFAULT_KEYS_SEARCH_LOCAL and DEFAULT_KEYS_SEARCH_GLOBAL).

Note that the mode selected here does not impact the default handling of system keys(因为起作用的都是以前没有handled的按键,比如数字键之类的。), such as the "back" and "menu" keys, and your activity and its views always get a first chance to receive and handle all application keys.

Parameters
mode The desired default key mode constant.
See Also
  • DEFAULT_KEYS_DISABLE
  • DEFAULT_KEYS_DIALER
  • DEFAULT_KEYS_SHORTCUT
  • DEFAULT_KEYS_SEARCH_LOCAL
  • DEFAULT_KEYS_SEARCH_GLOBAL
  • onKeyDown(int, KeyEvent)
再总结一下:setDefaultKeyMode的默认值是:DEFAULT_KEYS_DISABLE;所以点击一些数字键之类的没有反应,但是设置了DEFAULT_KEY_SEARCH_LOCAL以后,再次点击数字键,会启动本地搜索的功能,我想就是设置默认的按钮模式的问题。默认没反应,设置以后产生对应的操作。

转载于:https://www.cnblogs.com/joey-home/archive/2012/02/17/2355410.html

Activity中的setDefaultKeyMode() (转载)相关推荐

  1. android自定义view获取控件,android 自定义控件View在Activity中使用findByViewId得到结果为null...

    转载:http://blog.csdn.net/xiabing082/article/details/48781489 1.  大家常常自定义view,,然后在xml 中添加该view 组件..如果在 ...

  2. Activity中KeyEvent的传递

    2019独角兽企业重金招聘Python工程师标准>>> 我们先来写个测试应用,主要文件如下: MainActivity.java package com.test.keyevent; ...

  3. 在Activity中响应ListView内部按钮的点击事件的两种方法

    转载:http://www.cnblogs.com/ivan-xu/p/4124967.html 最近交流群里面有人问到一个问题:如何在Activity中响应ListView内部按钮的点击事件,不要在 ...

  4. 从Activity中返回数据

    从Activity中返回数据 一.简介 这里也就是使用intent方式返回数据. 二.具体步骤 在MainActivity通过一个button访问Activity01页面,然后将Activity01页 ...

  5. 基础问题:在一个 Activity 中定义的串口接收程序,如果 Activity 切换到其它 Activity 后还能接收到串口数据吗?...

    ====================问题描述==================== RT:基础问题:在一个 Activity 中定义的串口接收程序,如果 Activity 切换到其它 Activ ...

  6. 【Android】Intent介绍及Intent在Activity中的使用方法

    本篇博文主要介绍Intent的相关概念,以及Intent在Activity中的使用方法. 1.Intent的实现过程 在Android中,Intent不仅可用于应用程序之间的交互,也可用于应用程序内部 ...

  7. 【转】android之在activity中控制另一个activity的UI更新_如何在activity之间传递handler...

    来自:http://blog.csdn.net/jason0539/article/details/18055259 遇到一个问题,需要在一个activity中控制另一个acitivity做一些更新, ...

  8. 关于Activity的getReferrer():如何在Activity中获取调用者?

    http://blog.csdn.net/u013553529/article/details/53856800 关于Activity的getReferrer()之一:如何在Activity中获取调用 ...

  9. Android--使用剪切板在Activity中传值

    在Activity之间传递数据还可以利用一些技巧,不管windows还是Linux操作系统,都会支持一种叫剪切板的技术,也就是某一个程序将一些数据复制到剪切板上,然后其他的任何程序都可以从剪切板中获取 ...

  10. Android Activity中状态保存机制

    在Activity中保存用户的当前操作状态,如输入框中的文本,一般情况下载按了home键后,重新进入文本框中的东西会丢下,所以我们要保存当前页面信息,如在写短信的时候接到一个电话,那么当你接电话的时候 ...

最新文章

  1. 虚拟机下Linux安装图解之一:VMware Workstation的安装
  2. jieba分词中cut和lcut的区别
  3. XamarinAndroid组件教程设置动画的时长参数
  4. .NET 判断进程是否运行 是否未响应
  5. CSS属性中Display与Visibility
  6. xa 全局锁_fescar锁设计和隔离级别的理解
  7. 【pmcaff】看看人家的办公室 天天加班都愿意
  8. ejb 2.0 3.0_EJB 3.1全局JNDI访问
  9. Java:使用终止信号确定数据导入的状态
  10. python 数组维度_python – 非常基本的Numpy数组维度可视化
  11. 原生js设置div隐藏或者显示_10种JS控制DIV的显示隐藏代码
  12. Linux下查看CPU个数(逻辑个数和物理个数)
  13. 算法不会,尚能饭否之树(2)
  14. Vue之webpack之vue
  15. ES中的Multi_match深入解读:best_fields、most_fields、cross_fields用法一览
  16. 汽车高级驾驶辅助系统ADAS功能盘点
  17. Windows中命令行收集
  18. “黑球”行动再升级,SMBGhost漏洞攻击进入实战
  19. useSSL=false和true的区别
  20. Python+Excel+VBA实现批量自助生成名牌

热门文章

  1. 小D课堂 - 新版本微服务springcloud+Docker教程_3-04 SpringCloud微服务核心组件Eureka介绍和闭源后影响...
  2. 小D课堂 - 零基础入门SpringBoot2.X到实战_第11节 Logback日志框架介绍和SpringBoot整合实战_44、新日志框架LogBack介绍...
  3. 阶段3 3.SpringMVC·_07.SSM整合案例_02.ssm整合之搭建环境
  4. go 实现单链表反转
  5. 网站限制IP访问应该怎么办
  6. 博弈论:寻找先手必胜策略——Grundy值
  7. PHP下拉框内容随单选框内容变化
  8. POJ 1330 最近公共祖先LCA(Tarjan离线做法)
  9. BZOJ5312 冒险 势能分析、线段树
  10. 搭建基于hyperledger fabric的联盟社区(六) --搭建node.js服务器