Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
Widget
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Android Widget
Widget
Commits
35de26da
Commit
35de26da
authored
Jan 06, 2022
by
gaoyingxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自定义数字键盘
parent
6e4ceca7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
20 deletions
+11
-20
CommonKeyBoardKeyBoard.kt
.../java/com/qmai/android/keyboard/CommonKeyBoardKeyBoard.kt
+11
-19
activity_main.xml
app/src/main/res/layout/activity_main.xml
+0
-1
No files found.
KeyBoardView/src/main/java/com/qmai/android/keyboard/CommonKeyBoardKeyBoard.kt
View file @
35de26da
...
...
@@ -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)
//
}
}
}
//销毁
...
...
app/src/main/res/layout/activity_main.xml
View file @
35de26da
...
...
@@ -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"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment