android - 突出显示文本视图中的搜索文本不起作用
问题描述
#solved#当我构建时没有错误,但是在编辑文本中搜索特定文本并点击搜索按钮没有进行任何更改,即我的文本上没有突出显示。请帮助。下面是我的代码
// my java code
public void onClick(View v) {
String textTOHighlight=etText.getText().toString();
//delete this line String replacedWith = "<span style='background-color:yellow'>"+textTOHighlight+"</span>";
String originalText=textView.getText().toString();
// delete this line String modifiedText=originalText.replaceAll(textTOHighlight,replacedWith);
textView.setText(Html.fromHtml(modifiedText));
//added this and it works
String modifiedText=originalText.replaceAll(textTOHighlight, "<font color='red'>"+textTOHighlight+"</font>");
textView.setText(Html.fromHtml(modifiedText));
// strings.xml
<string-array name="chapters">
<item>this is just an example for first item</item>
<item>this is the second example <item>
</string-array>
// activity
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/et_text"
android:hint="Enter text"
android:padding="7dp"
android:layout_marginTop="10dp"
android:background="@drawable/bg_round"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/search"
android:text="Search"
android:layout_marginTop="10dp"
android:layout_marginStart="120dp"/>
<TextView
android:id="@+id/textv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="90dp"
android:scrollbars="vertical"
android:background="@drawable/bg_round"/>
解决方案
推荐阅读
- php - 如何通过 wordpress 页面上的插件呈现表单?
- analytics - couchbase 分析查询中是否允许 SELECT 中的双重计数
- list - 使用 OCaml 修剪对列表
- sql - SQL 如何透视这个表?
- python - Datetime 天数的子集
- apache - SameSite=None 不适用于 Apache 2.2.15 和 Tomcat 6
- c# - 查找范围之间的月份
- node.js - 无法从 localhost 获取数据
- php - Symfony / Mercure 问题:具有单一自我目标的 2 个用户都可以看到彼此所谓的循环消息
- minizinc - 检查 MiniZinc 数组中的项目