2013-09-26 41 views
0

我想查看一个PDF在Web视图中使用下面的代码,我可以查看它,但问题是,它打开一个新的视图,占据整个屏幕。我希望看到pdf应仅在Web视图中打开,而不能在新窗口中打开。 我使用下面的代码:Webview正在全屏android

 webView = (WebView) findViewById(R.id.webView); 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView.getSettings().setPluginsEnabled(true); 
     String pdf = "http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf"; 
     String url = "http://docs.google.com/gview?embedded=true&url=" + pdf; 
     webView.loadUrl(url); 

而下面是我的XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 


     <RelativeLayout 
     android:id="@+id/header_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/pdf_top_box" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:text="Title" 
      android:textColor="#ffffff" /> 

     <Button 
      android:id="@+id/back_pdf" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      android:background="@drawable/back_pdf" /> 
    </RelativeLayout> 

<WebView 
    android:id="@+id/webView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/header_layout" 
    /> 


</RelativeLayout> 
+2

是什么让你觉得你可以在Android的打开PDF的WebView? –

回答

1

尝试这种方式

webView = (WebView) findViewById(R.id.webView); 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView.getSettings().setPluginsEnabled(true); 
     String pdf = "http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf"; 
     String url = "http://docs.google.com/gview?embedded=true&url=" + pdf; 
     webView.setWebViewClient(new WebViewClient()); //UPDATE HERE 
     webView.loadUrl(url); 
+0

Works Perfect !!!感谢Biraj。 – Joyson