android 开发webview如何加载p标签的html

 我来答
匿名用户
推荐于2016-05-02
展开全部
本人弄的个类似实例以供参考:

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;

@SuppressLint("SetJavaScriptEnabled")
public class Onlinedic extends Activity {
        private TextView result;
        private EditText editText;
        private WebView webView;
        private String[] url = {"file:///android_asset/cn2en.html","file:///android_asset/en2cn.html",
                        "file:///android_asset/ge2cn.html","file:///android_asset/cn2ge.html",
                        "file:///android_asset/en2ge.html","file:///android_asset/ge2en.html"};
        private String[] chooseStr={"英","中","德","中","德","英"};
        private Handler tHandler = new Handler();
                
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.onlinedic);
        
        webView=(WebView)findViewById(R.id.toutput);
        final Button submit=(Button)findViewById(R.id.submit);
        editText=(EditText)findViewById(R.id.tinput);
        result=(TextView)findViewById(R.id.result);
        final Spinner l_select=(Spinner)findViewById(R.id.l_select);
  
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, 
                        android.R.layout.simple_spinner_item,chooseStr);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
        l_select.setPrompt("请选择翻译的方式");
        l_select.setOnItemSelectedListener(new OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                                if(((TextView)arg1).getText()==chooseStr[0])
                                        webView.loadUrl(url[0]);
                                if(((TextView)arg1).getText()==chooseStr[1])
                                        webView.loadUrl(url[1]);
                                if(((TextView)arg1).getText()==chooseStr[2])
                                        webView.loadUrl(url[2]);
                                if(((TextView)arg1).getText()==chooseStr[3])
                                        webView.loadUrl(url[3]);
                                if(((TextView)arg1).getText()==chooseStr[4])
                                        webView.loadUrl(url[4]);
                                if(((TextView)arg1).getText()==chooseStr[5])
                                        webView.loadUrl(url[5]);
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {
                                webView.loadUrl(url[0]);
                        }
                });
        l_select.setAdapter(adapter);
        
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSaveFormData(false);
        webSettings.setSavePassword(false);
        webSettings.setSupportZoom(false);
        
        submit.setOnClickListener(new OnClickListener() {                        
                        @Override
                        public void onClick(View v) {
                                result.setVisibility(TextView.VISIBLE);
                                webView.setVisibility(WebView.VISIBLE);
                                tHandler.post(new Runnable(){
                                public void run(){
                                  if (editText.getText().toString() != ""){
                                          webView.loadUrl("javascript:translate('"+ 
                                                          editText.getText().toString() + "')");
                                  }
                                }
                            });
                        }
                });
    }
}
落雨同乐3E
2015-06-18 · TA获得超过352个赞
知道小有建树答主
回答量:815
采纳率:66%
帮助的人:343万
展开全部
如果你要获取P的html代码 然后直接 loadUrl("html代码")就可以了;
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
baikewsp
推荐于2018-05-10 · TA获得超过1万个赞
知道小有建树答主
回答量:4588
采纳率:42%
帮助的人:689万
展开全部
本人弄的个类似实例以供参考:

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;

@SuppressLint("SetJavaScriptEnabled")
public class Onlinedic extends Activity {
private TextView result;
private EditText editText;
private WebView webView;
private String[] url = {"file:///android_asset/cn2en.html","file:///android_asset/en2cn.html",
"file:///android_asset/ge2cn.html","file:///android_asset/cn2ge.html",
"file:///android_asset/en2ge.html","file:///android_asset/ge2en.html"};
private String[] chooseStr={"英","中","德","中","德","英"};
private Handler tHandler = new Handler();

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.onlinedic);

webView=(WebView)findViewById(R.id.toutput);
final Button submit=(Button)findViewById(R.id.submit);
editText=(EditText)findViewById(R.id.tinput);
result=(TextView)findViewById(R.id.result);
final Spinner l_select=(Spinner)findViewById(R.id.l_select);

ArrayAdapter adapter=new ArrayAdapter(this,
android.R.layout.simple_spinner_item,chooseStr);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
l_select.setPrompt("请选择翻译的方式");
l_select.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView arg0, View arg1,
int arg2, long arg3) {
if(((TextView)arg1).getText()==chooseStr[0])
webView.loadUrl(url[0]);
if(((TextView)arg1).getText()==chooseStr[1])
webView.loadUrl(url[1]);
if(((TextView)arg1).getText()==chooseStr[2])
webView.loadUrl(url[2]);
if(((TextView)arg1).getText()==chooseStr[3])
webView.loadUrl(url[3]);
if(((TextView)arg1).getText()==chooseStr[4])
webView.loadUrl(url[4]);
if(((TextView)arg1).getText()==chooseStr[5])
webView.loadUrl(url[5]);
}

@Override
public void onNothingSelected(AdapterView arg0) {
webView.loadUrl(url[0]);
}
});
l_select.setAdapter(adapter);

WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSaveFormData(false);
webSettings.setSavePassword(false);
webSettings.setSupportZoom(false);

submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
result.setVisibility(TextView.VISIBLE);
webView.setVisibility(WebView.VISIBLE);
tHandler.post(new Runnable(){
public void run(){
if (editText.getText().toString() != ""){
webView.loadUrl("javascript:translate('"+
editText.getText().toString() + "')");
}
}
});
}
});
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式