开发者

Text viewed as HTML

Hey everyone this is a update from my previous question https://stackoverflow.com/questions/6676440/android-showing-a-edittext-text-in-webview

I got the webview to see the text inside my Edit text field but its dis开发者_运维技巧playing it as text this is the coding im using

    case R.id.Preview:
        Intent j = new Intent(this, Preview.class);
        j.putExtra(com.afajje.htmlzero.Preview.URL, 
                myEditText.getText().toString());
        startActivity(j);
}
return false;} 

Want im trying to have it do is view the Edit text, text as HTML

For example if I put in the Edittext field

<html>
<head>
</head>
<body>
<p>This is a Preview</p>
</body>
</html>

In the web view itll just just the "This is a Preview"


Here ya go, a working demo:

package com.stackexchange.test;

import android.app.Activity; 
import android.os.Bundle; 
import android.text.Html; 
import android.text.Spanned; 
import android.widget.EditText;

public class home extends Activity {

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

        EditText box = (EditText) findViewById(R.id.edittext);
        String htmltext = "<b>This is bold. </ b> and <i> this is italic </ i>." ; 
        Spanned text = Html.fromHtml( htmltext ); 
        box.setText( text );
    } 
}

You should see (except that I've edited the text in the app):

Text viewed as HTML


Try the below code to show the html text into the EditText.

 String str = "<html><head></head><body><p>This is a Preview</p></body></html>";
 editText = (EditText)findViewById(R.id.editText);
 editText.setText(Html.fromHtml(str));

Text viewed as HTML


Well, in the editText, if you dont use "Html.fromHtml", the string will be display with the html tags. In a WebView, I really dont know what zou want to do...sorry

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜