将箭头键添加到Android Studio中的键盘
我一直在尝试使用Android Studio在Android上编程自己的键盘。我想添加的一件事是移动光标的一些箭头键。我目前的键盘布局代码遵循此格式
<Row>
<Key android:keyLabel="..."
android:keyEdgeFlags="left"
android:codes="..."/>
<Key android:keyLabel="..."
android:codes="..."/>
<Key android:keyLabel="..."
android:keyEdgeFlags="right"
android:codes="..."/>
</Row>
,依此类推。
我不熟悉Android:代码。我了解您应该将HTML代码或Unicode字符的小数值放置,并且键盘函数(例如Enter或Delete)具有负值,例如-4或-5,但我真的不知道什么负数对应于什么功能。我真的找不到网上。从本质上讲,我不确定是否可以使用Android:代码移动光标,或者是否需要使用其他操作来完成光标。
I've been trying to program my own keyboard on android using android studio. One thing I wanted to add are some arrow keys to move the cursor. My current code for the layout of the keyboard follows this format
<Row>
<Key android:keyLabel="..."
android:keyEdgeFlags="left"
android:codes="..."/>
<Key android:keyLabel="..."
android:codes="..."/>
<Key android:keyLabel="..."
android:keyEdgeFlags="right"
android:codes="..."/>
</Row>
and so on.
I'm not familiar with the android:codes. I understand that you're supposed to put the html code or the decimal value of unicode characters, and keyboard functions like enter or delete have negative values, like -4 or -5, but I don't really know what negative number corresponds to what function. I can't really find it online. Essentially, I'm not sure if I can move the cursor with android:codes or if I need to use something else to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先 - 我根本不会使用这种方法。键盘视图已弃用。原因是没有严重的键盘使用它(甚至没有Google自己的),因此他们决定不进一步维护它。
其次 - 我认为您不能通过这种方法做到这一点。代码是Unicode字符。 Unicode没有光标移动命令。 Unicode没有光标的概念。您可以通过inputConnection呼叫轻松执行此操作(获取选择,更改它,然后设置了Selliction),左右,而不是通过Unicode字符。您需要设置这些键来调用一个函数,我不确定键盘视图是否可以。
第三键几乎是不可能的。原因是单词包裹。您不知道包裹线路断开的单词将在哪里发生,因此弄清楚在哪里几乎是不可能的。唯一可以做到这一点的是视图本身,并且在EditText中没有任何支持。您最好的选择是发送使用键盘_DPAD_UP或键盘_DPAD_DOWN的钥匙范围,并希望它有效)。
(另外,Enter和Delete不是负代码。输入是一个'\ n'字符,具有值。删除相同。但是它们都没有负值)。
First off- I wouldn't be using this approach at all. KeyboardView is deprecated. The reason is that no serious keyboard uses it (not even Google's own), so they decided not to maintain it further.
Secondly- I don't think you can do that via this method. Codes are unicode characters. Unicode doesn't have cursor movement commands. Unicode doesn't have the concept of a cursor. You could easily do this via InputConnection calls (get the selection, alter it, then set the selction), for left and right, but not via unicode characters. You'd need to set those keys to call a function, which I'm not sure if KeyboardView can do.
Third- up and down keys will be almost impossible to do. The reason is word wrapping. You have no idea where the word wrapping linebreaks will occur, so figuring out where 1 line down is will be next to impossible. The only thing that could really do that is the view itself, and there's no support for that in EditText. Your best bet here would be to send a KeyEvent with a KEYBOARD_DPAD_UP or KEYBOARD_DPAD_DOWN and hope it works).
(Also, enter and delete aren't negative codes. Enter is a '\n' character, and has a value. Same for delete. But none of them have negative values).