You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
FruitsProject/app/src/main/java/com/example/Fruits/WebViewActivity.java

37 lines
1.3 KiB

package com.example.Fruits;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
public class WebViewActivity extends AppCompatActivity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view_activity);
mWebView = (WebView) findViewById(R.id.web_view);
Intent intent = getIntent();
String url = null;//"https://baike.baidu.com/item/"+intent.getStringExtra("url"); //"https://baidu.com/";//
//try {
url = "https://baike.baidu.com/item/"+intent.getStringExtra("url")+"?&ie=utf-8&oe=UTF-8&wd=";//+ URLEncoder.encode("西瓜","UTF-8");
//} catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
mWebView.loadUrl(url);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient(){
});
}
@Override
public void onBackPressed() {
if (mWebView != null && mWebView.canGoBack()){
mWebView.goBack();
}else {
super.onBackPressed();
}
}
}