Android 中的 WebView 问题
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 视图和在 Web 视图中加载 http://www.google.com 网址,但问题是 Web 视图显示 Google.com模拟器不在实际设备中。
请帮我。
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();
}
}
I am Using Above Code for Display Web View & Load http://www.google.com URL in Web View but Problem is The WebView is Display Google.com in Emulator not in Actual Device.
Please Help Me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论