Skip to content

Commit 780ffcc

Browse files
perf: 优化焦点获取
1 parent c4f0c5f commit 780ffcc

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

app/src/main/java/com/chenlittleping/filltextview/FillTextView.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class FillTextView: View, MyInputConnection.InputListener, View.OnKeyListener {
147147
}
148148

149149
private fun init() {
150+
isFocusable = true
150151
initCursorPaint()
151152
initTextPaint()
152153
initFillPaint()
@@ -482,6 +483,8 @@ class FillTextView: View, MyInputConnection.InputListener, View.OnKeyListener {
482483
}
483484

484485
override fun onTouchEvent(event: MotionEvent): Boolean {
486+
isFocusableInTouchMode = true
487+
requestFocus()
485488
when (event.action) {
486489
MotionEvent.ACTION_DOWN -> {
487490
if (touchCollision(event)) {

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
android:id="@+id/fillText"
1212
android:layout_width="match_parent"
1313
android:layout_height="wrap_content"
14-
android:layout_alignParentBottom="true"
15-
app:fillTextSize="16sp"
14+
app:layout_constraintTop_toTopOf="parent"
1615
android:layout_marginLeft="10dp"
1716
android:layout_marginRight="10dp"
17+
app:fillTextSize="16sp"
1818
app:rowSpace="3dp"
1919
app:fillColor="@android:color/holo_blue_dark"
2020
app:filledText="大家好,我是<fill>,我来自<fill>。我就是来填个空而已<fill>"/>

0 commit comments

Comments
 (0)