I am using WebView
to justify text. I want to know-
Is it possible to set the text size in
layout
file? As I want different text size for different screen sizes.And also one problem is first background appears then after 2 second text display. Is it possible to display text immediately?
Size of text is 7-8 lines.
Code-
public class Main extends Activity {
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
String text = "<html><body>"+"<p align=\"justify\">"+getString(R.string.itext)+"</p>"+"</body></html>";
mWebView .loadData(text, "text/html", "utf-8");
mWebView .setBackgroundColor(Color.TRANSPARENT);
}
}
Xml-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/light">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"/>
</LinearLayout>
I'm not sure if this is what you're looking for, but as long as you don't want to set the text size based on a calculation with the text width/height, this should be what you're looking for:
This way you're getting the settings of the
WebView
whose text size you're trying to change.There're some predefined values you can set as size using the
TextSize
class, for instance:You could simply choose which one you need to set depending on the parameters of the current device that you choose.
If you, on the contrary, want to make some kind of screen width/height calculation and set the result as a particular value, you may even use this:
---- EDIT ----
To enhace your
WebView
rendering, try the following:You could also try adding this to your
Manifest
file: