All of the above answers will not delete the html tag, for example, etc., if this line contains, I tried to delete all the tags, and this works fine for me
AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setTitle("Title"); LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_dialog, null); TextView text = (TextView) layout.findViewById(R.id.text); text.setMovementMethod(LinkMovementMethod.getInstance()); text.setText(Html.fromHtml("<b>Hello World</b> This is a test of the URL <a href=http://www.example.com> Example</a><p><b>This text is bold</b></p><p><em>This text is emphasized</em></p><p><code>This is computer output</code></p><p>This is<sub> subscript</sub> and <sup>superscript</sup></p>";)); builder.setView(layout); AlertDialog alert = builder.show();
and custom_dialog will look like this:
<TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textColor="#FFF" />
The above code will remove the entire html tag and display the example as "Click capable URL" to all others in the specified html formatting text.
source share