


TextView advanced application: TextView displays Html format content and pictures_html/css_WEB-ITnose
TextView is one of the most commonly used components in our development. The most commonly used function is mainly used for text display. You can set the text size, color and other effects. If you think that the function of TextView is only used to display text, you are totally wrong. It has more uses, such as displaying pictures, realizing some text click events, and realizing URLs, mobile phone numbers with links, etc., all of which can be used in TextView. Once realized. Be strong!
TextView is often used in projects to display text in Html format. I will simply post it today. Take a note.
-------------------------Simple layout main_test_html.xml, just a TextView--------- ---------------------
< ;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation= "vertical" >
🎜> android:padding="10dp"
/>
--- --------------------Realize display of html format text in Activity---------------------- ---------
public class TestActivity extends Activity {
private TextView htmlTv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_test_html);
/**Get TextView control*/
htmlTv = (TextView) findViewById(R.id. text);
/**We piece together the Html format string ourselves*/
String mHtmlStr = "Html TextView
";
mHtmlStr = "Bold and italic text
";
mHtmlStr = "With link, click to jump directly to Sina, haha";
/* *To use Html.fromHtml, convert the string containing HTML tags into displayable text (CharSequence: the parent class of String, StringBuffer, etc.) style*/
CharSequence charSequence = Html.fromHtml(mHtmlStr);
// Assign value to TextView through setText
htmlTv.setText(charSequence);
/**************What if we want to add pictures to TextView?****************************** *************/
/**To use the Html class ImageGetter interface*/
ImageGetter imageGetter = new ImageGetter() {
@Override
public Drawable getDrawable(String source) {
int id = Integer.parseInt (source);
Drawable drawable = getResources().getDrawable(id);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
return drawable;
}
};
/**You can display pictures through the following methods*/
htmlTv.setText(Html.fromHtml("", imageGetter, null));
}
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...
