6 个答案:
答案 0 :(得分:19)
这是Webview的一个小怪癖,它有一个白色的默认背景颜色,绘制在任何drawable之前。您需要使用以下代码使其透明并显示您的可绘制背景:
WebView webview = (WebView)findViewById(R.id.webView1);
webview.setBackgroundColor(0);
答案 1 :(得分:14)
唯一的方法是通过其他视图(例如FrameLayout)包装WebView元素,并在外部视图上应用圆角背景。
例如:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:paddingLeft="1dip"
android:paddingRight="1dip"
android:background="@drawable/white_rounded_area"
>
android:id="@+id/web_view"
android:layout_width="300dip"
android:layout_height="400dip"
android:layout_gravity="center"
/>
paddingTop和paddingBottom等于drawable / white_rounded_area的半径,
paddingLeft和paddingRight等于笔触宽度drawable / white_rounded_area。
这种方法的缺点是顶部底部圆形面板可以与WebView内的网页具有不同的背景颜色,尤其是在页面滚动时。
答案 2 :(得分:4)
试试这个
android:shape="rectangle" >
android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
android:color="@drawable/black"
android:width="3dp"/>
答案 3 :(得分:0)
您可以使用CardView来包含Web视图,而只需要使用app:cardCornerRadius添加所需的拐角半径:
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="10dp"> // HERE
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
就这些
答案 4 :(得分:0)
我使用的图像看起来像一个相框,我在框架中给出了圆角。我把这个相框放在上我试图给圆角的视图。
诀窍是使用RelativeLayout;将您的布局放在其中。
在布局下方添加另一个ImageView,将其background设置为合适的遮罩图像框。这将在您的其他布局之上绘制。
就我而言,我制作了一个灰色背景的9Patch文件,并从中剪下了透明的圆角矩形。

这为您的底层布局创建了完美的遮罩。
XML代码可能是这样的:
android:layout_height="wrap_content" android:layout_width="fill_parent">
android:layout_width="fill_parent"
android:background="@drawable/grey_frame"
android:layout_alignTop="@+id/mainLayout"
android:layout_alignBottom="@+id/mainLayout" />
完整的详细信息可以在我的原始答案中找到:
答案 5 :(得分:0)
这些解决方案都不适合我。
它对我有用。在加载数据之前,您需要设置
webView.getSettings().setUseWideViewPort(true);
并将您应用于XML文件中。
它对我有用。
这篇博客讨论了Android WebView显示圆角的问题,包括通过设置WebView背景透明、使用 Framelayout 包裹、设置 CardView 的 cardCornerRadius 属性以及应用特定的 Shape 资源等方法。文章提供了多个解决方案,以应对不同情况下的需求。
970

被折叠的 条评论
为什么被折叠?



