O
O
Oleksandr Shcherbak2020-05-16 14:57:44
Java
Oleksandr Shcherbak, 2020-05-16 14:57:44

How to insert an image into html text?

There is text in html, in the assets folder. Insert an image (png) into this text. Here's how I do it:

....На спомин Господа Бога і Спаса нашого Ісуса Христа <font COLOR='RED'>(тричі).</font><br />
<p style="text-align: center;">
<img src='" + getResources().getDrawable(R.drawable.proskomydiya_1)"'/>
</p><br />
І надрізує копієм з правого боку печатки (з лівої руки священика)...

In DetailsActivity I write the code:
Html.ImageGetter imageGetter = new Html.ImageGetter() {

        @Override
        public Drawable getDrawable(String source) {

            Drawable d;
            if(string_title.contains("lit_1_part_2" ) || string_title.contains("lit_2_part_2")){
                d = getResources().getDrawable(R.drawable.proskomydiya_1);
            } else {
                d = getResources().getDrawable(R.drawable.proskomydiya_2);
            }

            d.setBounds(0, 0, d.getIntrinsicWidth()/2, d.getIntrinsicHeight()/2);
            return d;

But the picture is either too big or too small.

5ebfd4584f965803632185.png
How to correctly bind the width and height of the image to the screen size? I tried like this, but nothing good came of it.
int width = getWindowManager().getDefaultDisplay().getWidth();
 int height = getWindowManager().getDefaultDisplay().getWidth();
            d.setBounds(0, 0, width, height);
            return d;

Like this, it also doesn't work for some reason:
<img src='" + getResources().getDrawable(R.drawable.proskomydiya_1)"' width="200" height="200"/>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question