Skip to content Skip to sidebar Skip to footer

Android Insert An Image From Strings.xml File

Hi guys I need to use some images inside my book. My app is using fragments and ViewPager for displaying texts and by changing page it shows new string on same TextView so I can't

Solution 1:

The easiest way will be to use a WebView, which allows you to format the object perfectly using html and also allows to manages the text alignment , wight, font, size etc .

try using a webview and proceed as follows.

WebView view=(WebView) findViewById(R.id.webViev);
        String data=new String();


        data="<html><head></head><body><b>CHAPTER ONE</b> \n\n<b>The Boy Who Lived</b><br/><imgsrc=\"file:///android_asset/photo.jpg\"  height=\"150\" width=\"150\"/><p>Mr. and Mrs. Dursley, of number four, Privet Drive, were proud to say that they       were perfectly normal, thank you very much. They were the last people you’d expect to be   involved in anything strange or mysterious, because they just didn’t hold with such   nonsense.Mr. Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large mustache. Mrs. Dursley was thin and blonde and had nearly twice the usual amount of neck, which came in very useful as she spent so much of her time craning over garden fences, spying on the neighbors. The Dursleys had a small son called Dudley and in their opinion there was no finer boy anywhere.</p></body></html>";

        view.loadDataWithBaseURL(null, data,"text/html", "utf-8",null); 

You can use the string data in your strings.xml file. And the image to be loaded is placed in the assets folder of the android porject. Both jpg and png formats will work for image. You can use the baseUrL and historyURL.

Post a Comment for "Android Insert An Image From Strings.xml File"