Skip to content

Commit 0f9312c

Browse files
committed
Set parent view focusability programmatically
1 parent 980129f commit 0f9312c

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121

2222
<FrameLayout
2323
android:layout_width="match_parent"
24-
android:layout_height="wrap_content"
25-
android:focusable="true"
26-
android:focusableInTouchMode="true" >
24+
android:layout_height="wrap_content" >
2725

2826
<org.wordpress.aztec.AztecText
2927
android:id="@+id/aztec"

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121

2222
<FrameLayout
2323
android:layout_width="match_parent"
24-
android:layout_height="wrap_content"
25-
android:focusable="true"
26-
android:focusableInTouchMode="true" >
24+
android:layout_height="wrap_content" >
2725

2826
<org.wordpress.aztec.AztecText
2927
android:id="@+id/aztec"

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,12 +778,21 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
778778
disableTextChangedListener()
779779
val selStart = selectionStart
780780
val selEnd = selectionEnd
781-
clearFocus()
781+
setFocusOnParentView()
782782
text = editableText
783783
setSelection(selStart, selEnd)
784784
enableTextChangedListener()
785785
}
786786

787+
fun setFocusOnParentView() {
788+
if (parent is View) {
789+
val parentView = parent as View
790+
parentView.isFocusable = true
791+
parentView.isFocusableInTouchMode = true
792+
parentView.requestFocus()
793+
}
794+
}
795+
787796
fun removeInlineStylesFromRange(start: Int, end: Int) {
788797
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_BOLD, start, end)
789798
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_ITALIC, start, end)

0 commit comments

Comments
 (0)