cdg*_*cdg 44 android refresh reload webview
好.我一直在寻找,而我的小脑子却无法理解更新活动的更好方法.我能理解的任何建议都会很棒.:)
这是java代码:
package com.dge.dges;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
public class dgeActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings();
mWebView.loadUrl("http://www.websitehere.php");
Button newButton = (Button)findViewById(R.id.new_button);
newButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(dgeActivity.this, dgeActivity.class);
startActivity(intent);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
这是main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
/>
<Button
android:id="@+id/new_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Refresh"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我不喜欢在活动后重新堆叠活动的想法.必须有一种更简单的方法来刷新webview.请帮忙.:)
Pen*_*m10 62
1)如果您想重新加载相同的URL:
mWebView.loadUrl("http://www.websitehere.php");
Run Code Online (Sandbox Code Playgroud)
所以完整的代码将是
newButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dgeActivity.this.mWebView.loadUrl("http://www.websitehere.php");
}});
Run Code Online (Sandbox Code Playgroud)
2)mWebView.reload()如果请求是POST,你也可以打电话但要知道这会重新发布一个页面,所以只能在GET上正常工作.
dra*_*oot 44
最好的解决方案就是做webView.loadUrl( "javascript:window.location.reload( true )" );.这应适用于所有版本,不会引入新的历史记录条目.
Tho*_*401 11
这对我有用.
刚刚放入onCreate metode
Button button = (Button) findViewById(R.id.reload_btn);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
web.loadUrl( "javascript:window.location.reload( true )" );
}
});
Run Code Online (Sandbox Code Playgroud)
这是可以在webView中重新加载网站的代码
web.loadUrl( "javascript:window.location.reload( true )" );
Run Code Online (Sandbox Code Playgroud)
尝试这个 :
mWebView.loadUrl(mWebView.getUrl().toString());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
123421 次 |
| 最近记录: |