【问题标题】:Android - Problem with WebViewAndroid - WebView 的问题
【发布时间】:2011-03-09 13:23:59
【问题描述】:

我对此很纠结,并多次解析网络以了解以下内容。

我正在使用一个嵌入 WebView 的简单 Activity:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/tables"
</LinearLayout>

如您所见,我正在尝试应用可绘制形状 (android:background="@drawable/tables"),以便 WebView 具有圆角、描边边框......

问题是 WebView 没有得到我试图设置的任何外观(没有圆角等......)。

我要应用的形状的代码:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <solid   android:color="@color/fond_tables"/>
     <corners android:bottomRightRadius="10dp"
              android:bottomLeftRadius="10dp" 
              android:topLeftRadius="10dp"
              android:topRightRadius="10dp"/> 
     <stroke  android:width="3dp"
              android:color="@color/bordure_tables" />
</shape>

感谢任何可以帮助我解决此问题的人。

提前致谢

亚当。

【问题讨论】:

    标签: android webview shape


    【解决方案1】:

    我也遇到了同样的问题。后来我知道我们不能改变 webView 背景。您可以更改布局背景。我试过这种方法效果很好。

    <TableRow
        android:id="@+id/tableRow5"
    
        android:background="@drawable/fullshape"
    
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp" >
    
        <WebView
            android:id="@+id/webView1"
            android:layout_width="280dp"
            android:layout_height="280dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp" />
    
    </TableRow>
    

    【讨论】:

      【解决方案2】:
      WebView webview = (WebView)findViewById(R.id.webView);        
      webview.setBackgroundColor(0);
      

      通过应用透明背景色,webview 将使用布局中的背景。

      【讨论】:

      • 虽然这个答案可能是正确且有用的,但最好在其中附上一些解释来解释它如何帮助解决问题。如果有更改(可能不相关)导致它停止工作并且用户需要了解它曾经是如何工作的,这在未来变得特别有用。
      猜你喜欢
      • 1970-01-01
      • 2019-05-16
      • 2015-06-25
      • 1970-01-01
      • 2011-09-24
      • 1970-01-01
      • 1970-01-01
      • 2017-12-18
      • 2015-04-02
      相关资源
      最近更新 更多