本文介绍了Android的自定义键盘2 lablels(主要和小右上方)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我实现我自己的自定义键盘。
I am implementing my own custom keyboard.
我用实现键盘
<?xml version="1.0" encoding="utf-8"?>
<Row>
<Key android:keyLabel="q" android:keyEdgeFlags="left"/>
<Key android:keyLabel="w"/>
<Key android:keyLabel="e"/>
<Key android:keyLabel="r"/>
<Key android:keyLabel="t"/>
<Key android:keyLabel="y"/>
<Key android:keyLabel="u"/>
<Key android:keyLabel="i"/>
<Key android:keyLabel="o"/>
<Key android:keyLabel="p" android:keyEdgeFlags="right"/>
</Row>
我想有2个标签上关键button.The一样对下图(红色):
I want have 2 label on key button.The same as on image below (red):
我如何更改键盘XML有这个?当我们在长按按钮,我们应该选择数字而不是字母
How can I change the keyboard xml to have this? When we make the long click on button we should choose numbers instead of letters
推荐答案
您需要创建一个KeyboardView扩展类并重写的OnDraw方法是这样的:
you need to create a KeyboardView extends class and override OnDraw method like this:
public class MKeyboardView extends KeyboardView {
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setTextSize(15);
paint.setColor(Color.GRAY);
List<Key> keys = getKeyboard().getKeys();
for(Key key: keys) {
if(key.codes[0] == 113)
canvas.drawText("1", key.x + (key.width/2), key.y + 25, paint);
}
}
}
您可以通过改变x和y参数改变位置。
you can change the position by changing the x and y parameters.
享受:)
这篇关于Android的自定义键盘2 lablels(主要和小右上方)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!