Activity中的setDefaultKeyMode()

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


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

[java]  view plain copy
  1. /** 
  2.      * Use with {@link #setDefaultKeyMode} to turn off default handling of 
  3.      * keys. 
  4.      *  
  5.      * @see #setDefaultKeyMode 
  6.      */  
  7.     static public final int DEFAULT_KEYS_DISABLE = 0//如果设为这个,则在activity中按键的不做响应  
  8.     /** 
  9.      * Use with {@link #setDefaultKeyMode} to launch the dialer during default 
  10.      * key handling. 
  11.      *  
  12.      * @see #setDefaultKeyMode 
  13.      */  
  14.     static public final int DEFAULT_KEYS_DIALER = 1//如果设为这个,则在activity中按键会打开拨号器  
  15.   
  16.     /** 
  17.      * Use with {@link #setDefaultKeyMode} to execute a menu shortcut in 
  18.      * default key handling. 
  19.      *  
  20.      * <p>That is, the user does not need to hold down the menu key to execute menu shortcuts. 
  21.      *  
  22.      * @see #setDefaultKeyMode 
  23.      */  
  24.     static public final int DEFAULT_KEYS_SHORTCUT = 2//如果设为这个,则在activity中按键会启动快键键  
  25.     /** 
  26.      * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes 
  27.      * will start an application-defined search.  (If the application or activity does not 
  28.      * actually define a search, the the keys will be ignored.) 
  29.      *  
  30.      * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. 
  31.      *  
  32.      * @see #setDefaultKeyMode 
  33.      */  
  34.     static public final int DEFAULT_KEYS_SEARCH_LOCAL = 3//如果设为这个,则在activity中按键会打开本地搜索  
  35.   
  36.     /** 
  37.      * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes 
  38.      * will start a global search (typically web search, but some platforms may define alternate 
  39.      * methods for global search) 
  40.      *  
  41.      * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. 
  42.      *  
  43.      * @see #setDefaultKeyMode 
  44.      */  
  45.     static public final int DEFAULT_KEYS_SEARCH_GLOBAL = 4//如果设为这个,则在activity中按键会打开全局搜索  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值