Android: give a webview rounded corners?
android, java, rounded-corners
Solution
The only way is wrap WebView element by other view (FrameLayout for example), and apply rounded corners background on external view. Example:
<FrameLayout
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"
>
<WebView
android:id="@+id/web_view"
android:layout_width="300dip"
android:layout_height="400dip"
android:layout_gravity="center"
/>
</FrameLayout>
Where paddingTop and paddingBottom equals radius from drawable/white_rounded_area, paddingLeft and paddingRight equals stroke width drawable/white_rounded_area.
Minus of this approach is top an bottom rounded panels can have different background color with web page inside WebView, especially when page scrolled.
Problem
I'm trying to give my webView rounded corners. Here is my code: rounded_webview.xml: ``` <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp"> <solid android:color="#000"/> <corners android:bottomRightRadius="15dp" android:bottomLeftRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/> </shape> ``` And here is my webView: ``` <WebView android:id="@+id/webView1" android:layout_width="293dp" android:layout_height="142dp" android:layout_gravity="center_horizontal" android:padding="5dip" android:background="@drawable/rounded_webview"/> ``` But it simply won't work! Corners are not rounded...