在网页上显示其他解决方案时,网页上的其他解决方案仍然重复或下降,而不是使用我的代码
所以我是noob阶段的HTML / CSS开发人员。我正在尝试为我的网站构建一个简单的webview应用程序。现在,当我从github获得一个用于webview的项目时,似乎“文件上传”在webview中不起作用,但在浏览器中就像一个魅力。请帮帮我。此外,如果应用程序的整个意图只是将网站转换为Android应用程序,如果您认为github上有一个项目可以很容易达到我的目的(webview中的文件上传),那么你可以给我链接!谢谢!
我的MainActivity.java:
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
// Force links and redirects to open in the WebView instead of in a browser
mWebView.setWebViewClient(new WebViewClient());
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// Use remote resource
// mWebView.loadUrl("http://example.com");
// Stop local links and redirects from opening in browser instead of WebView
// mWebView.setWebViewClient(new MyAppWebViewClient());
// Use local resource
mWebView.loadUrl("file:///android_asset/www/index.html");
}
// Prevent the back-button from closing the app
@Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
根据您的期望,我认为您希望在WebView中启用繁重的任务。为此,您需要启用 ChromeClient ,
mWebView.setWebChromeClient(new MyWebViewClient());
你的MyWebViewClient类将是,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
// Force links and redirects to open in the WebView instead of in a browser
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebChromeClient(new MyWebViewClient()); // HERE
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// Use remote resource
// mWebView.loadUrl("http://example.com");
// Stop local links and redirects from opening in browser instead of WebView
// mWebView.setWebViewClient(new MyAppWebViewClient());
class MyWebViewClient extends WebChromeClient {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
}
}
// Use local resource
mWebView.loadUrl("file:///android_asset/www/index.html");
}
希望这能帮到你!