我使用 Android 键盘类创建了自定义键盘。
我想要两种模式的行。一种是普通模式。一种是当用户按下“Sym”按钮时。对于 XML 中“Sym”按钮的每个 Keyboard.Row,我指定了 android:keyboardMode="@+id/sym"。
现在,当我运行它时,只显示未指定 android:keyboardMode 的行。这是预期的,也是文档所说的。
我的问题是如何在我的代码中设置模式,以便渲染带有 android:keyboardMode="@+id/sym"的行?
<Row>
<Key android:codes="113" android:keyLabel="q" />
<Key android:codes="119" android:keyLabel="w" />
<Key android:codes="101" android:keyLabel="e" />
<Key android:codes="114" android:keyLabel="r" />
<Key android:codes="116" android:keyLabel="t" />
<Key android:codes="121" android:keyLabel="y" />
<Key android:codes="117" android:keyLabel="u" />
<Key android:codes="105" android:keyLabel="i" />
<Key android:codes="111" android:keyLabel="o" />
<Key android:codes="112" android:keyLabel="p" />
<Key android:codes="-5" android:keyIcon="@drawable/keyboard_backspace_icon" android:keyWidth="91dp" />
</Row>
<Row android:keyboardMode="@+id/sym">
<Key android:codes="113" android:keyLabel="+" />
<Key android:codes="119" android:keyLabel="_" />
<Key android:codes="101" android:keyLabel="=" />
<Key android:codes="114" android:keyLabel="%" />
<Key android:codes="116" android:keyLabel="^" />
<Key android:codes="121" android:keyLabel="|" />
<Key android:codes="117" android:keyLabel="<" />
<Key android:codes="105" android:keyLabel=">" />
<Key android:codes="111" android:keyLabel="[" />
<Key android:codes="112" android:keyLabel="]" />
<Key android:codes="-5" android:keyIcon="@drawable/keyboard_backspace_icon" android:keyWidth="91dp" />
</Row>
最佳答案
好吧,我自己想出来了。
没有简单切换键盘模式的方法。您需要做的是创建 2 个不同的键盘并在它们之间手动切换。
这是更新后的 XML 的样子。请注意,您在两个关键字中都需要的行不应包含标志 android:keyboardMode。
<!-- this is the row that shows in both modes -->
<Row android:keyWidth="51dp">
<Key android:codes="49" android:keyLabel="1" />
<Key android:codes="50" android:keyLabel="2" />
<Key android:codes="51" android:keyLabel="3" />
<Key android:codes="52" android:keyLabel="4" />
<Key android:codes="53" android:keyLabel="5" />
<Key android:codes="54" android:keyLabel="6" />
<Key android:codes="55" android:keyLabel="7" />
<Key android:codes="56" android:keyLabel="8" />
<Key android:codes="57" android:keyLabel="9" />
<Key android:codes="48" android:keyLabel="0"/>
</Row>
<!-- this is the normal mode -->
<Row android:keyboardMode="@integer/keyboard_normal">
<Key android:codes="113" android:keyLabel="q" />
<Key android:codes="119" android:keyLabel="w" />
<Key android:codes="101" android:keyLabel="e" />
<Key android:codes="114" android:keyLabel="r" />
<Key android:codes="116" android:keyLabel="t" />
<Key android:codes="121" android:keyLabel="y" />
<Key android:codes="117" android:keyLabel="u" />
<Key android:codes="105" android:keyLabel="i" />
<Key android:codes="111" android:keyLabel="o" />
<Key android:codes="112" android:keyLabel="p" />
<Key android:codes="-5" android:keyIcon="@drawable/keyboard_backspace_icon" android:keyWidth="91dp" />
</Row>
<!-- this is the symbol mode-->
<Row android:keyboardMode="@integer/keyboard_symbol">
<Key android:codes="113" android:keyLabel="+" />
<Key android:codes="119" android:keyLabel="_" />
<Key android:codes="101" android:keyLabel="=" />
<Key android:codes="114" android:keyLabel="%" />
<Key android:codes="116" android:keyLabel="^" />
<Key android:codes="121" android:keyLabel="|" />
<Key android:codes="117" android:keyLabel="<" />
<Key android:codes="105" android:keyLabel=">" />
<Key android:codes="111" android:keyLabel="[" />
<Key android:codes="112" android:keyLabel="]" />
<Key android:codes="-5" android:keyIcon="@drawable/keyboard_backspace_icon" android:keyWidth="91dp" />
</Row>
然后创建一个integer.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="keyboard_symbol">1</integer>
<integer name="keyboard_normal">0</integer>
</resources>
这里是相关的java代码。当您创建键盘对象时,您传递 keyboard_normal 或 keyboard_symbol。
normalKeyBoard = new Keyboard(activity, R.id.board, R.integer.keyboard_normal);
symbolKeyBoard = new Keyboard(activity, R.id.board, R.integer.keyboard_symbol);
现在创建一个类变量来跟踪模式。默认值为 R.integer.keyboard_normal
private int mKeyboardState = R.integer.keyboard_normal;
现在在您的 onKeyboardActionListner().onKey 方法中放置代码以捕获切换模式的键(假设您已经在键盘中创建了一个)。
if( primaryCode== Keyboard.KEYCODE_MODE_CHANGE) {
if(mKeyboardView != null) {
if(mKeyboardState == R.integer.keyboard_normal){
//change to symbol keyboard
if(symbolKeyBoard== null){
symbolKeyBoard = new Keyboard(mHostActivity, R.xml.hexkbd, R.integer.keyboard_symbol);
}
mKeyboardView.setKeyboard(symbolKeyBoard);
mKeyboardState = R.integer.keyboard_symbol;
} else {
if(normalKeyBoard== null){
normalKeyBoard = new Keyboard(mHostActivity, R.xml.hexkbd, R.integer.keyboard_normal);
}
mKeyboardView.setKeyboard(normalKeyBoard);
mKeyboardState = R.integer.keyboard_normal;
}
//no shifting
mKeyboardView.setShifted(false);
}
}
关于android - 在android自定义键盘中设置键盘模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16174179/
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我正在尝试在Ruby中制作一个cli应用程序,它接受一个给定的数组,然后将其显示为一个列表,我可以使用箭头键浏览它。我觉得我已经在Ruby中看到一个库已经这样做了,但我记不起它的名字了。我正在尝试对soundcloud2000中的代码进行逆向工程做类似的事情,但他的代码与SoundcloudAPI的使用紧密耦合。我知道cursesgem,我正在考虑更抽象的东西。广告有没有人见过可以做到这一点的库或一些概念证明的Ruby代码可以做到这一点? 最佳答案 我不知道这是否是您正在寻找的,但也许您可以使用我的想法。由于我没有关于您要完成的工作
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano