Commit 35de26da authored by gaoyingxiang's avatar gaoyingxiang

自定义数字键盘

parent 6e4ceca7
......@@ -28,9 +28,6 @@ class CommonKeyBoardKeyBoard : KeyboardView {
var rightTopBtn: String? = null
var clearTextColor:Int? = null
var clearTextSize:Float? = null
//是否可以使用点
var pointColor:Int? = null
var pointSize:Float? = null
//获取drawable资源
......@@ -114,7 +111,7 @@ class CommonKeyBoardKeyBoard : KeyboardView {
key.y + (key.height) / 2 - (fontMetrics.bottom - fontMetrics.top) / 2
//绘制文字
canvas.drawText(
rightTopBtn?:"取消",
rightTopBtn?:"清空",
(key.x + ((key.width) / 2)).toFloat(),
baseLine + key.height / 2,
mtextPaint
......@@ -124,10 +121,7 @@ class CommonKeyBoardKeyBoard : KeyboardView {
//开始绘制
if (key.label != null) {
val fontMetrics = mtextPaint.fontMetrics
if (pointColor!=null&&pointColor!=0){
mtextPaint.color = pointColor?:mClearDefaultColor
}
mtextPaint.textSize = sp2px(pointSize?:15f)
mtextPaint.textSize = sp2px(15f)
mtextPaint.textAlign = Paint.Align.CENTER
mtextPaint.color = Color.parseColor("#333333")
//计算基线
......@@ -135,9 +129,9 @@ class CommonKeyBoardKeyBoard : KeyboardView {
key.y + (key.height) / 2 - (fontMetrics.bottom - fontMetrics.top) / 2
//绘制文字
canvas.drawText(
".",
"",
(key.x + ((key.width) / 2)).toFloat(),
baseLine + key.height / 3,
baseLine + key.height / 2,
mtextPaint
)
}
......@@ -189,10 +183,8 @@ class CommonKeyBoardKeyBoard : KeyboardView {
20 -> {
editable.append(".")
}
21 -> {
editable.append("00")
}
Code.SAVE.code -> {
}
else -> {
editable.append(primaryCode.toString())
......@@ -254,12 +246,12 @@ class CommonKeyBoardKeyBoard : KeyboardView {
clearTextSize = typedArray.getDimension(
R.styleable.CommonKeyBoardKeyBoardStyleable_clearTextSize,15f)
}
R.styleable.CommonKeyBoardKeyBoardStyleable_pointColor->{
pointColor = typedArray.getColor(R.styleable.CommonKeyBoardKeyBoardStyleable_pointColor,0)
}
R.styleable.CommonKeyBoardKeyBoardStyleable_pointSize->{
pointSize = typedArray.getDimension(R.styleable.CommonKeyBoardKeyBoardStyleable_pointSize,15f)
}
// R.styleable.CommonKeyBoardKeyBoardStyleable_pointColor->{
// pointColor = typedArray.getColor(R.styleable.CommonKeyBoardKeyBoardStyleable_pointColor,mClearDefaultColor)
// }
// R.styleable.CommonKeyBoardKeyBoardStyleable_pointSize->{
// pointSize = typedArray.getDimension(R.styleable.CommonKeyBoardKeyBoardStyleable_pointSize,15f)
// }
}
}
//销毁
......
......@@ -127,7 +127,6 @@
android:keyTextSize="16sp"
android:verticalGap= "10dp"
android:shadowColor="#ffffff"
app:pointSize = "120dp"
android:keyBackground="@drawable/stockbtn_keyboard_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment