问题描述
这是我的Java代码,我的textview中有一个大文本,我想搜索单词并将其突出显示,这样就很容易找到bt,我不想在输入编辑文本后立即创建按钮它应该突出显示该词。 这是我所做的工作,直到我在编辑文本中输入一些单词,但我希望突出显示的单词能帮助我
public class sample extends AppCompatActivity implements {
TextView textView;
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle("sample");
if (getIntent().hasExtra("a1")) {
Stribg data= getIntent().getStringExtra("a1");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a2")) {
String data = getIntent().getStringExtra("a2");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a3")) {
String data = getIntent().getStringExtra("a3");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a4")) {
String data = getIntent().getStringExtra("a4");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a5")) {
String data = getIntent().getStringExtra("a5");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a6")) {
String data = getIntent().getStringExtra("a6");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a7")) {
String data = getIntent().getStringExtra("a7");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a8")) {
String data = getIntent().getStringExtra("a8");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a9")) {
String data = getIntent().getStringExtra("a9");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a10")) {
String data = getIntent().getStringExtra("a10");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a11")) {
String data = getIntent().getStringExtra("a11");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a12")) {
String data = getIntent().getStringExtra("a12");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a13")) {
String data = getIntent().getStringExtra("a13");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a14")) {
String data = getIntent().getStringExtra("a14");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a15")) {
String data = getIntent().getStringExtra("a15");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a16")) {
String data = getIntent().getStringExtra("a16");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a17")) {
String data = getIntent().getStringExtra("a17");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
} else if (getIntent().hasExtra("a18")) {
String data = getIntent().getStringExtra("a18");
TextView textView = findViewById(R.id.Text1);
textView.setText(data);
}
public void onClick(View view) {
String textToHighlight=editText.getText().toString();
String replaceWith="<span style='background-color:yellow'>"+textToHighlight+"</span>";
String originalText = textView.getText().toString();
String modifiedtext= originalText.replaceAll(textToHighlight,replaceWith);
textView.setText(Html.fromHtml(modifiedtext));
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)