Skip to content

Commit a4df930

Browse files
committed
添加光标高度属性
1 parent 5c43752 commit a4df930

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

library/src/main/java/com/lwjfork/code/CodeEditText.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class CodeEditText extends EditText {
6565
private boolean showCursor;// 是否显示光标
6666
private int cursorDuration;// 光标闪烁间隔
6767
private int cursorWidth;// 光标宽度
68+
private int cursorHeight;// 光标高度
6869
@ColorInt
6970
private int cursorColor;// 光标颜色 没有设置时默认字体颜色
7071

@@ -129,9 +130,10 @@ private void parseAttrs(Context context, AttributeSet attrs, int defStyleAttr, i
129130

130131
showCursor = typedArray.getBoolean(R.styleable.CodeEditText_showCursor, false);
131132
cursorDuration = typedArray.getInteger(R.styleable.CodeEditText_cursorDuration, 500);
132-
cursorWidth = typedArray.getDimensionPixelSize(R.styleable.CodeEditText_blockCorner, dp2px(1));
133+
cursorWidth = typedArray.getDimensionPixelSize(R.styleable.CodeEditText_cursorWidth, dp2px(1));
134+
cursorHeight = typedArray.getDimensionPixelSize(R.styleable.CodeEditText_cursorHeight, (int) (codeTextSize * 1.25f));
133135
cursorColor = typedArray.getColor(R.styleable.CodeEditText_cursorColor, blockNormalColor);
134-
cursorDrawer = createCursorDrawer(showCursor, cursorDuration, cursorWidth, cursorColor);
136+
cursorDrawer = createCursorDrawer(showCursor, cursorDuration, cursorWidth, cursorHeight, cursorColor);
135137
typedArray.recycle();
136138
}
137139

@@ -144,8 +146,8 @@ private void parseAttrs(Context context, AttributeSet attrs, int defStyleAttr, i
144146
* @param cursorColor
145147
* @return
146148
*/
147-
private CursorDrawer createCursorDrawer(boolean showCursor, int cursorDuration, int cursorWidth, int cursorColor) {
148-
return new CursorDrawer(showCursor, cursorDuration, cursorWidth, cursorColor);
149+
private CursorDrawer createCursorDrawer(boolean showCursor, int cursorDuration, int cursorWidth, int cursorHeight, int cursorColor) {
150+
return new CursorDrawer(showCursor, cursorDuration, cursorWidth, cursorHeight, cursorColor);
149151
}
150152

151153
/**

library/src/main/java/com/lwjfork/code/cusor/CursorDrawer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ public class CursorDrawer extends BaseDrawer {
1616
private boolean showCursor;// 是否显示光标
1717
private int cursorDuration;// 光标闪烁间隔
1818
private int cursorWidth;// 光标宽度
19+
private int cursorHeight;// 光标高度
1920
@ColorInt
2021
private int cursorColor;// 光标颜色 没有设置时默认黑色
2122
private Paint cursorPaint;
2223

23-
public CursorDrawer(boolean showCursor, int cursorDuration, int cursorWidth, int cursorColor) {
24+
public CursorDrawer(boolean showCursor, int cursorDuration, int cursorWidth, int cursorHeight,int cursorColor) {
2425
this.showCursor = showCursor;
2526
this.cursorDuration = cursorDuration;
2627
this.cursorWidth = cursorWidth;
2728
this.cursorColor = cursorColor;
29+
this.cursorHeight = cursorHeight;
2830
iniPaint();
2931
}
3032

library/src/main/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
<attr name="cursorDuration" format="integer" />
4949
<!--光标宽度-->
5050
<attr name="cursorWidth" format="dimension" />
51+
<!--光标高度-->
52+
<attr name="cursorHeight" format="dimension" />
5153
<!--光标颜色 没有设置时默认取 codeTextColor 颜色-->
5254
<attr name="cursorColor" format="color|reference" />
5355
</declare-styleable>

0 commit comments

Comments
 (0)