问题描述
我是新来的机器人。我正在开发Android设备的EPUB阅读器。 web视图显示左对齐文本。我希望它可以自圆其说。我不知道这是文本对齐方式的问题。
I am new to android. I am developing epub reader for android devices. webview shows text in left alignment. i want it to be justify. i am not sure this is text alignment problem.
这是我的WebView设置:
This is my webview settings:
final WebView mainWebView = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
mainWebView.setWebViewClient(new MyCustomWebViewClient());
mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mainWebView.loadUrl("my html page");// loding my html pages here
mainWebView.getSettings().setUseWideViewPort(true);
我用这个code文本对齐
i used this code for text alignment
mainWebView.loadUrl("javascript:(function addCSSRule(selector, newRule) { " +
"var mySheet = document.styleSheets[0];"+
"if (mySheet.addRule) { " +
"mySheet.addRule(selector, newRule);" +
"} else {"+
"ruleIndex = mySheet.cssRules.length;"+
"mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);" +
"}"+
"})addCSSRule(selector, newRule)");
mainWebView.loadUrl("javascript:addCSSRule('p', 'text-align: justify;');");
如果我删除 mainWebView.getSettings()setUseWideViewPort(真);
意味着我得到对齐文本
if i remove mainWebView.getSettings().setUseWideViewPort(true);
means i am getting justify text.
网页流量的屏幕截图:
我希望它是这样的:
我不知道什么是错在我的code。 mainWebView.getSettings()setUseWideViewPort(真);
允许放大。不知道为什么它杀死文本对齐方式。请大家帮我解决这个问题。
先谢谢了。
i don't know whats wrong in my code. mainWebView.getSettings().setUseWideViewPort(true);
allows to zoom. don't know why it kills text alignment. please help me to overcome this issue.Thanks in advance.
推荐答案
这似乎并不像你申请你webSettings到Web视图。我在寻找沿
It doesn't seem like you're applying your webSettings to the web view. I'm looking for something along the lines of
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);
因此,也许你的JavaScript不点火,因为它不是......?
so perhaps your javascript isn't firing because it's not on... ?
这篇关于在android系统的WebView文本对齐方式获取问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!