1

I want to set newline in web view in android side values from XML.I am using (/n) tags in XML but it not accepted.I don't know how make new line in paragraph and also i want to set background image in webview image from drawable folder...

    protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.rsslistitemdesc);
    Bundle b = getIntent().getExtras();
    desc=(WebView) findViewById(R.id.description);
    itemdesc=getIntent().getExtras().getString("desc");          
    String htmlText = "%s ";
    String description = "<html><body>" + "<p align=\"justify\" >"+"<font color=\"black\"><br>"+ b.getString("desc")+ "<br/></p>" + "</body></html>";
    desc.loadData(String.format(htmlText, description), "text/html", "utf-8");
    desc.setBackgroundColor(0);
    desc.setBackgroundResource(Color.TRANSPARENT);     
}

    example.xml
    <item>
    <title></title>        
    <desc>A summary of your objectives,educational qualification,experience,skills    relevant to the field of work you are going to enter.Here you can detail down each.It highlights your accomplishments to show a potential employer that you are qualified for the work you want.Remember it is not a biography of everything you have done.Its core PURPOSE is to get you an interview.A resume can or should reflect more than just your education.As a fresher the experience lies in the projects,seminars,workshops etc. you pursue during your academics.Showcase your important details like extra – curricular,volunteer &amp; leadership experiences.Tailoring separate resumes to fit each career field in which you are job searching may be important.Some people create slightly different resumes tailored to each job opening.
    </desc>
    </item>
Arun Raj
  • 243
  • 1
  • 7
  • 21
  • Show some code that you have tried so far.It would be easy to answer. – Spring Breaker Jul 30 '13 at 06:17
  • hi user2012 this code i have tried so far but values from xml that is a problem i don't know to how to make a newline in paragraph and in-between in paragraph and also i want to set background image from drawable folder – Arun Raj Jul 30 '13 at 06:55

2 Answers2

4

You can use "<br>" tag to do the task.See the below example,

 desc=(WebView) findViewById(R.id.description);
String webdata="<html><body><p>To break lines<br>in a text,<br>use the br element./p</body</html>"
 desc.loadData(webdata, "text/html", "utf-8");

This will result the following output,

To break lines
in a text,
use the br element.
Spring Breaker
  • 8,233
  • 3
  • 36
  • 60
0

You can use,

System.getProperty("line.separator") or "\n" for new line.

To set background,follow this link.

Click here

Community
  • 1
  • 1
Srinivasan
  • 4,481
  • 3
  • 28
  • 36
  • hi sri but values from xml how can i make new line.I use this code b.getString("desc") means it get all the values from particular tag and displays in webview.so,how can i make a newline in-between in paragraph and background color also not set – Arun Raj Jul 30 '13 at 06:48
  • Try this one ,myWebView.setBackgroundColor(Color.BLUE); remove the setBackgroundResources() method. And you cant able to add break in the middle as you did.You have to get the string value in StringBuilder sb =b.getString("desc"); and you have to explicitly append the "
    " tag where ever you want and then give it to html tag.
    – Srinivasan Jul 30 '13 at 07:16
  • sorry sri i'm not getting values from string.xml i'm using xml parsing see the above xml file – Arun Raj Jul 30 '13 at 07:34