html-textview
html-textview copied to clipboard
Cardview not clickable with HtmlTextView as Child
I have a simple cardview that contains a htmltextview. But upon compiling, I'm not able to click the cardview and the htmltextview is in focus instead. I tried defining the htmltextview as not clickable or focusable, but to no success. Is there a way to click a cardview that contains the htmltextview? (htmltextview matches cardviews width and height).
<androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/newscenter_cardView"
android:layout_width="match_parent"
android:layout_height="299dp"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="@android:color/white"
app:cardMaxElevation="1dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:contentPadding="10dp"
app:contentPaddingBottom="0dp">
<org.sufficientlysecure.htmltextview.HtmlTextView
android:id="@+id/newscenter_htmlview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:textAppearance="@android:style/TextAppearance.Small" />
</androidx.cardview.widget.CardView>
I am having a similar issue. The HtmlText does not allow for duplicateParentState=True attribute so allow for clickable
I have the same problem. It's due to setMovementMethod(..)
being called in setHtml(..)
in source code. If I got it right this call makes every HtmlTextView you use clickable by default therefore makes it intercept click events.
public void setHtml(@NonNull String html, @Nullable Html.ImageGetter imageGetter) {
final HtmlTagHandler htmlTagHandler = new HtmlTagHandler(getPaint());
htmlTagHandler.setClickableTableSpan(clickableTableSpan);
htmlTagHandler.setDrawTableLinkSpan(drawTableLinkSpan);
htmlTagHandler.setListIndentPx(indent);
html = htmlTagHandler.overrideTags(html);
if (removeTrailingWhiteSpace) {
setText(removeHtmlBottomPadding(Html.fromHtml(html, imageGetter, htmlTagHandler)));
} else {
setText(Html.fromHtml(html, imageGetter, htmlTagHandler));
}
// make links work
setMovementMethod(LocalLinkMovementMethod.getInstance());
}
Solution was to use setMovementMethod(null);
after setHtml()
.
You must disable forcus cardview, set setOnTouchListener in htmlTextView with call onTouchEvent of CardView
htmlTextView.setOnTouchListener((v, event) -> {
itemView.findViewById(R.id.layout_child).onTouchEvent(event);
return false;
});