new Keyboard(this, R.layout.samplelayout);
使用具有单一键盘布局的布局文件。我想做的是制作一个文件,并在其中有多个键盘布局,应该可以通过他们的ID访问..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:id="@+id/symszzzzzzzzz">
<Row>
<Key android:codes="0" android:keyLabel="~" android:keyEdgeFlags="left"/>
<Key android:codes="1" android:keyLabel="+" android:keyOutputText="+"/>
<Key android:codes="2" android:keyLabel="x" android:keyOutputText="x"/>
<Key android:codes="3" android:keyLabel="÷" android:keyOutputText="÷"/>
<Key android:codes="4" android:keyLabel="•" android:keyOutputText="•"/>
<Key android:codes="5" android:keyLabel="°" android:keyOutputText="°"/>
<Key android:codes="6" android:keyLabel="`" android:keyOutputText="`"/>
<Key android:codes="7" android:keyLabel="´" android:keyOutputText="´"/>
<Key android:codes="8" android:keyLabel="{" android:keyOutputText="{"/>
<Key android:codes="9" android:keyLabel="}" android:keyEdgeFlags="right" android:keyOutputText="}"/>
</Row>
<Row>
<Key android:codes="10" android:keyLabel="©" android:keyEdgeFlags="left" android:keyOutputText="©"/>
<Key android:codes="11" android:keyLabel="£" android:keyOutputText="£"/>
<Key android:codes="12" android:keyLabel="€" android:keyOutputText="€"/>
<Key android:codes="13" android:keyLabel="^" android:keyOutputText="^"/>
<Key android:codes="14" android:keyLabel="®" android:keyOutputText="®"/>
<Key android:codes="15" android:keyLabel="¥" android:keyOutputText="¥"/>
<Key android:codes="16" android:keyLabel="_" android:keyOutputText="_"/>
<Key android:codes="17" android:keyLabel="+" android:keyOutputText="+"/>
<Key android:codes="18" android:keyLabel="[" android:keyOutputText="[]"/>
<Key android:codes="19" android:keyLabel="]" android:keyEdgeFlags="right" android:keyOutputText="]"/>
</Row>
<Row>
<Key android:codes="20" android:keyLabel="¡" android:horizontalGap="5%p"
android:keyEdgeFlags="left" android:keyOutputText="¡"/>
<Key android:codes="21" android:keyLabel="<" android:keyOutputText="<"/>
<Key android:codes="22" android:keyLabel=">" android:keyOutputText=">"/>
<Key android:codes="23" android:keyLabel="¢" android:keyOutputText="¢"/>
<Key android:codes="24" android:keyLabel="|" android:keyOutputText="|"/>
<Key android:codes="25" android:keyLabel="\\" android:keyOutputText="\\"/>
<Key android:codes="26" android:keyLabel="¿" android:keyOutputText="¿"/>
<Key android:codes="27" android:keyLabel="l" android:keyOutputText="l"/>
<Key android:codes="-5" android:keyLabel="Back"
android:keyWidth="15%p" android:keyEdgeFlags="right"
android:isRepeatable="true"/>
</Row>
<Row android:rowEdgeFlags="bottom">
<Key android:codes="-3" android:keyLabel="\@" android:horizontalGap="20%p"
android:keyWidth="15%p" android:keyEdgeFlags="left" android:keyOutputText="\@"/>
<Key android:codes="-2" android:keyLabel=".com" android:keyWidth="15%p"/>
<Key android:codes="-1" android:keyLabel="SFT"
android:keyWidth="15%p" android:isRepeatable="true"/>
<Key android:codes="-4" android:keyLabel="."
android:keyWidth="15%p" android:keyEdgeFlags="right"/>
</Row>
</Keyboard>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:id ="@+id/qwertyzzzzzzzzzz" >
<Row>
<Key android:codes="0" android:keyLabel="1" android:keyOutputText="1" android:keyEdgeFlags="left"/>
<Key android:codes="1" android:keyLabel="2" android:keyOutputText="2"/>
<Key android:codes="2" android:keyLabel="3" android:keyOutputText="3"/>
<Key android:codes="3" android:keyLabel="4" android:keyOutputText="4"/>
<Key android:codes="4" android:keyLabel="5" android:keyOutputText="5"/>
<Key android:codes="5" android:keyLabel="6" android:keyOutputText="6"/>
<Key android:codes="6" android:keyLabel="7" android:keyOutputText="7"/>
<Key android:codes="7" android:keyLabel="8" android:keyOutputText="8"/>
<Key android:codes="8" android:keyLabel="9" android:keyOutputText="9"/>
<Key android:codes="9" android:keyLabel="0" android:keyOutputText="0" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="10" android:keyLabel="q" android:keyOutputText="q" android:keyEdgeFlags="left"/>
<Key android:codes="11" android:keyLabel="w" android:keyOutputText="w"/>
<Key android:codes="12" android:keyLabel="e" android:keyOutputText="e"/>
<Key android:codes="13" android:keyLabel="r" android:keyOutputText="r"/>
<Key android:codes="14" android:keyLabel="t" android:keyOutputText="t"/>
<Key android:codes="15" android:keyLabel="y" android:keyOutputText="y"/>
<Key android:codes="16" android:keyLabel="u" android:keyOutputText="u"/>
<Key android:codes="17" android:keyLabel="i" android:keyOutputText="i"/>
<Key android:codes="18" android:keyLabel="o" android:keyOutputText="o"/>
<Key android:codes="19" android:keyLabel="p" android:keyOutputText="p" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="20" android:keyLabel="a" android:horizontalGap="5%p"
android:keyEdgeFlags="left" android:keyOutputText="a"/>
<Key android:codes="21" android:keyLabel="s" android:keyOutputText="s"/>
<Key android:codes="22" android:keyLabel="d" android:keyOutputText="d"/>
<Key android:codes="23" android:keyLabel="f" android:keyOutputText="f"/>
<Key android:codes="24" android:keyLabel="g" android:keyOutputText="g"/>
<Key android:codes="25" android:keyLabel="h" android:keyOutputText="h"/>
<Key android:codes="26" android:keyLabel="j" android:keyOutputText="j"/>
<Key android:codes="27" android:keyLabel="k" android:keyOutputText="k"/>
<Key android:codes="28" android:keyLabel="l" android:keyOutputText="l" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="29" android:keyLabel="z" android:horizontalGap="7%p"
android:keyEdgeFlags="left" android:keyOutputText="z"/>
<Key android:codes="30" android:keyLabel="x" android:keyOutputText="x"/>
<Key android:codes="31" android:keyLabel="c" android:keyOutputText="c"/>
<Key android:codes="32" android:keyLabel="v" android:keyOutputText="v"/>
<Key android:codes="33" android:keyLabel="b" android:keyOutputText="b"/>
<Key android:codes="34" android:keyLabel="n" android:keyOutputText="n"/>
<Key android:codes="35" android:keyLabel="m" android:keyOutputText="m"/>
<Key android:codes="-5" android:keyLabel="Back"
android:keyWidth="15%p" android:keyEdgeFlags="right"
android:isRepeatable="true"/>
</Row>
<Row android:rowEdgeFlags="bottom">
<Key android:codes="-3" android:keyLabel="\@" android:horizontalGap="20%p"
android:keyWidth="15%p" android:keyEdgeFlags="left"/>
<Key android:codes="-2" android:keyLabel=".com" android:keyWidth="15%p"/>
<Key android:codes="-1" android:keyLabel="SFT"
android:keyWidth="15%p" android:isRepeatable="true"/>
<Key android:codes="-4" android:keyLabel="."
android:keyWidth="15%p" android:keyEdgeFlags="right"/>
</Row>
</Keyboard>
</LinearLayout>
而不是提供这整个文件我想传递布局的ID。但是,当我尝试这个时,我得到以下错误
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): FATAL EXCEPTION: main
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ritu.keyboard/com.ritu.keyboard.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f050002 type #0x12 is not valid
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.os.Handler.dispatchMessage(Handler.java:99)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.os.Looper.loop(Looper.java:123)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.app.ActivityThread.main(ActivityThread.java:3647)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at java.lang.reflect.Method.invoke(Method.java:507)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at dalvik.system.NativeStart.main(Native Method)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f050002 type #0x12 is not valid
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.content.res.Resources.getXml(Resources.java:780)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.inputmethodservice.Keyboard.<init>(Keyboard.java:528)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.inputmethodservice.Keyboard.<init>(Keyboard.java:505)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at com.ritu.keyboard.MainActivity.onCreate(MainActivity.java:26)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
07-03 19:27:27.455: ERROR/AndroidRuntime(2462): ... 11 more
如何实现这一目标?