0

So in Android I wanted to justify the text so I decided to use the Webview.It works fine but the only issue I have is that the background of my app is not white. So whenever I see the text, it always has a white background. So can I add a body tag to enable it to change the background color?

String text = "<html><body style=\"text-align:justify\"> %s </body> </Html> ";
     // I want to include a body tag above which will make the background this color = #e6e6e6
       String data = "My Text";

       WebView webView = (WebView) findViewById(R.id.WebView);
       webView.loadData(String.format(text, data), "text/html", "utf-8");

2 Answers 2

1

Take a look at the following link. Android TextView Justify Text

It explains the justify rules in android. How to do it in webview and it also has a support library you could use to do native.

Try

webView.setBackgroundColor("#00000000")

for transparent background.

Sign up to request clarification or add additional context in comments.

Comments

0

Try:

String text = "<html><body style=\"text-align:justify; background-color:#e6e6e6;\"> %s </body></html>"

The background-color CSS property should let you set the background to whatever you want it to be.

Edit: Kalel Wade's answer is better since it's done through the Android properties as opposed to the HTML.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.