android 불러오기 디스플레이 풍부한 텍스트 - TextView 디스플레이 풍부한 텍스트 및 WebView 디스플레이 풍부한 텍스트, WebView 디스플레이 그림 화면 폭

4996 단어
TextView 로드 디스플레이
의존성 추가
implementation 'com.zzhoujay.richtext:richtext:3.0.8'
implementation 'com.zzhoujay:html:1.0.2'

호출
/**
 *   Html
 *
 * @param html
 */
protected void loadHtml(String html, TextView textContent) {
    try {
        RichText.fromHtml(html).into(textContent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

 
WebView 로드 디스플레이
1. 웹뷰 봉인
public class LollipopFixedWebView extends WebView {

    public LollipopFixedWebView(Context context) {
        super(getFixedContext(context));
    }

    public LollipopFixedWebView(Context context, AttributeSet attrs) {
        super(getFixedContext(context), attrs);
    }

    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(getFixedContext(context), attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
    }

    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
        super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
    }

    public static Context getFixedContext(Context context) {
        if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) // Android Lollipop 5.0 & 5.1
            return context.createConfigurationContext(new Configuration());
        return context;
    }
}

2. 인용

3. 자바 코드 구현
방법 1
String topss="";
LgqLogutil.e("lll000ll===  "+content);
String endss="";

방법 2
 
String js = ""+
        "var imgs = document.getElementsByTagName('img');" + //   img  
        "for(var i = 0; i<imgs.length; i++){" +  //     
        "imgs[i].style.width = '100%';" +  //     100%
        "imgs[i].style.height = 'auto';" +
        "}" +
        "";

   webView.loadData((data.getProjectDescription()+js).replace("&zoom=640w",""), "text/html;charset=utf-8", null);
webView.loadData((ss+js).replace("&zoom=640w",""), "text/html;charset=utf-8", null);
  public void initfte(String ss){
        WebSettings settings = webView.getSettings();
        //   WebView  JavaScript
        settings.setJavaScriptEnabled(true);
        //      
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setSupportZoom(false);  //      
        settings.setBuiltInZoomControls(false); //      
        settings.setBlockNetworkImage(true);//               
        settings.setAllowFileAccess(true); //       
        settings.setSaveFormData(true);
        settings.setGeolocationEnabled(true);
        settings.setDomStorageEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);///     JS     
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        //          
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }
        });

        //        
        webView.setWebChromeClient(new WebChromeClient());
        // mWebView.loadUrl(TEXTURL);

        //           
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
            webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        webView.getSettings().setBlockNetworkImage(false);

        //  cookie           
        CookieManager mCookieManager = CookieManager.getInstance();
        mCookieManager.setAcceptCookie(true);
        mCookieManager.setAcceptThirdPartyCookies(webView, true);
        webView.loadDataWithBaseURL(null,ss, "text/html" , "utf-8", null);//  html  
//        webView.loadUrl(URL);
    }

 
bug 온라인 커뮤니케이션: QQ1085220040

좋은 웹페이지 즐겨찾기