简体   繁体   中英

How to show Text and Images in a TextView

This is the json response below from ifeng api.

在此处输入图片说明

Please help me how to show text object in a TextView including images in the middle.

使用webwiev并在webview上加载以下json响应(文本女巫以html格式)。

Try This First pars that data ,then get text from text param

After getting the HTML text You need to use Html.fromHtml()

If your you are targeting < Android Nougat

yourTextView.setText(Html.fromHtml("PUT YOUR HTML CODE HERE"));

If your you are targeting >= Android Nougat

yourTextView.setText(Html.fromHtml("PUT YOUR HTML CODE HERE", Html.FROM_HTML_MODE_COMPACT));

Note:-

To distinguish between Android versions use Build.VERSION.SDK_INT >= Build.VERSION_CODES.N

Happy Coding!!

Try using TextView.setText(Html.fromHtml(...)) , then using html tags in ... , but you need to implement Html.ImageGetter

Reference: https://stackoverflow.com/a/7442725/1636610

you can show image in textview as drawable like below -

tvTitle.setText("Hi");
tvTitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);//it will show icon image on left side of the text on tvTitle text view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM