Webview,样式表相对路径int url

时间:2012-04-26 10:30:26

标签: android webview

  <base href="http://www.myurl.com/">
        <link href="templates/default/css/mycss.css?1" rel="stylesheet" type="text/css" />

我正在尝试使用andrid webview加载网址。页面已加载但没有css。有一种方法(对于相对路径)。有没有办法直接使用css加载页面而不进行缓存并使用loadDataWithBaseURL打开它?

谢谢你的推荐

1 个答案:

答案 0 :(得分:0)

试试这个......

    Description = (WebView)findViewById(R.id.webView1);
    Description.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    Description.getSettings().setJavaScriptEnabled(true);
    Description.getSettings().setBuiltInZoomControls(true);
    //PodcastDescription.setTextSize(20.f);
    //PodcastDescription.setTypeface(tf);

    Bundle mybundle = getIntent().getExtras();
    Integer NewsNumber = mybundle.getInt("number");


    String CurrentDescription = Entertainment.Description[NewsNumber];




    Description.loadDataWithBaseURL (null, "<html><head><style>@font-face{font-family:'MeeraRegular'; src: url('file:///android_asset/fonts/Meera.ttf');}body{font-family:'MeeraRegular'; font-size:20px; } </style></head><body>"+CurrentDescription+"</body></html>", "text/html", "UTF-8",
    null);