由网友(无缘相守却又无法忘记)分享简介:我使用的WebView 来对齐文本。我想知道 - 是否有可能设置在布局中的文字大小文件?因为我想不同的文字大小不同的屏幕尺寸。 和也是一个问题是第一次出现的背景,然后经过2第二个文本显示。是否有可能立即显示的文字? 文本的大小是7-8线 code - 公共类主要扩展活动{的WebView mWebView;@覆...
我使用的WebView
来对齐文本。我想知道 -
是否有可能设置在布局中的文字大小
文件?因为我想不同的文字大小不同的屏幕尺寸。
和也是一个问题是第一次出现的背景,然后经过2第二个文本显示。是否有可能立即显示的文字?
文本的大小是7-8线
code -
公共类主要扩展活动{
的WebView mWebView;
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
mWebView =(web视图)findViewById(R.id.webview);
字符串文本=< HTML><身体GT;+< p ALIGN = 证明>中+的getString(R.string.itext)+< / P>中+< /身体GT;< / HTML>中;
mWebView .loadData(文字,text / html的,UTF-8);
mWebView .setBackgroundColor(Color.TRANSPARENT);
}
}
XML -
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@可绘制/光>
<的WebView
机器人:ID =@ + ID / web视图
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@机器人:彩色/透明/>
< / LinearLayout中>
解决方案
有关从布局设置文字大小 -
最后WebSettings webSettings = web.getSettings();
资源RES = getResources();
fontSize的= res.getDimension(R.dimen.txtSize);
webSettings.setDefaultFontSize((INT)fontSize的);
即时文本显示 -
webSettings.setRenderPriority(RenderPriority.HIGH);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setAppCacheEnabled(假);
webSettings.setBlockNetworkImage(真正的);
webSettings.setLoadsImagesAutomatically(真正的);
webSettings.setGeolocationEnabled(假);
webSettings.setNeedInitialFocus(假);
webSettings.setSaveFormData(假);
在值的文件夹 -
<资源>
<扪名=txtSize> 26sp< /扪>
< /资源>
希望工程。
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>
解决方案
For setting text size from layout-
final WebSettings webSettings = web.getSettings();
Resources res = getResources();
fontSize = res.getDimension(R.dimen.txtSize);
webSettings.setDefaultFontSize((int)fontSize);
For Immediate text display-
webSettings.setRenderPriority(RenderPriority.HIGH);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setAppCacheEnabled(false);
webSettings.setBlockNetworkImage(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setGeolocationEnabled(false);
webSettings.setNeedInitialFocus(false);
webSettings.setSaveFormData(false);
In values folder-
<resources>
<dimen name="txtSize">26sp</dimen>
</resources>
Hope it works.
相关推荐
最新文章