我正在尝试在android中开发custome软键盘,我想在按下键时更改键的输出文本的颜色,我的想法是通过以下代码使类扩展键:
public class k extends Key{
private Paint mTextPaint;
public k(Resources arg0, Row arg1, int arg2, int arg3,XmlResourceParser arg4) {
super(arg0, arg1, arg2, arg3, arg4);
initLabelView();
AttributeSet attributes = Xml.asAttributeSet(arg4);
TypedArray a =arg0.obtainAttributes(attributes, R.styleable.LabelView);
setTextColor(a.getColor(R.styleable.LabelView_textColor, 0xFF000000));
a.recycle();
initLabelView();
}
private final void initLabelView() {
mTextPaint = new Paint();
mTextPaint.setAntiAlias(true);
mTextPaint.setTextSize(16);
mTextPaint.setColor(0xFF000000);
}
public void setTextColor(int color) {
mTextPaint.setColor(color);
}
}
并在 value 文件夹中设置 attrs xml 文件(如自定义视图)
并在 xml 文件夹 II 中为键盘制作了 xml 文件,通过以下代码由行和键组成:
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" android:keyWidth="14.28%p"
xmlns:app="http://schemas.android.com/apk/res/com.szlosek.keying"
android:horizontalGap="0px" android:verticalGap="0px" android:keyHeight="@dimen/key_height">
<Row>
<Key android:codes="121"
android:textColor="#26E80C"
android:keyLabel="d"/>
<com.szlosek.keying.k
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:codes="117"
app:textColor="#26E80C"
android:keyLabel="u" />
-->
</Row>
</Keyboard>
我的问题是我自定义它的键(有标签 u)没有出现在键盘中,而另一个出现(如标签)请任何人帮助我并编辑我的代码谢谢