I'm pulling my hair around this and have parsed the web several times to understand the following开发者_StackOverflow中文版.
I'm using a simple Activity which embeds a WebView:
<?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>
As you can see, I'm trying to apply a drawable shape (android:background="@drawable/tables"
) so that the WebView has rounded corners, a stroke border, ...
Problem is that the WebView does not get any of the apparence I'm trying to set (no rounded corners, etc...).
The code of the shape I'm trying to apply :
<?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>
I would be grateful to anyone who could help me solving this issue.
thanks in advance
Adam.
I faced the same issue too. Later I know we can't change the webView background. You can change the layout background. I have tried this method working fine.
<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>
WebView webview = (WebView)findViewById(R.id.webView);
webview.setBackgroundColor(0);
By applying background color transparent, webview will use background from layout.
精彩评论