main.xml中: -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/rlayout1">
<Button android:layout_width="wrap_content" android:text="Back"
android:layout_centerVertical="true" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_marginLeft="5dip"
android:id="@+id/mBtnBackMore" />
<TextView android:layout_width="wrap_content"
android:layout_centerVertical="true" android:layout_centerHorizontal="true"
android:textColor="#ffffff" android:textSize="22dip"
android:textStyle="bold" android:layout_height="wrap_content"
android:text="More" android:id="@+id/txtviewfbdisplaytitle" />
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_below="@+id/rlayout1"
android:id="@+id/rlayout2">
<WebView android:id="@+id/mWebViewMore" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
</RelativeLayout>
Main_Activity.Java: -
public class Main_Activity extends Activity implements OnClickListener {
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
System.out.println("URL is:- " +url);
return true;
}
}
Button btnBack;
WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.more);
webview=(WebView)findViewById(R.id.mWebView);
webview.setWebViewClient(new MyWebViewClient());
openURL();
btnBack = (Button) findViewById(R.id.mBtnBack);
btnBack.setOnClickListener(this);
}
/** Opens the URL in a browser */
private void openURL() {
webview.loadUrl("http://www.google.com");
webview.requestFocus();
}
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
}
我使用上面的代码显示Web视图&amp;在Web视图中加载http://www.google.com URL,但问题是WebView在模拟器中显示Google.com而不是在实际设备中。
请帮助我。