Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use edittext as html editor in android

Tags:

java

android

i am creating an application which give options to write articles and submit.

I want to give all html options to user so that user can make part of text bold,italic,underlined etc. i googled but not found that much suitable options or any html tool for android.

looking for suggestions.

like image 824
ankita gahoi Avatar asked Apr 13 '26 18:04

ankita gahoi


1 Answers

You can use something like below for this :

Here textDisplayedBottom is a TextView.

actualStringToDisplay="font COLOR=\"RED\"><b>"+yourString</b></font>"; 
textDisplayedBottom.setText(Html.fromHtml(actualStringToDisplay));

Hope this helps.

EDIT 1: For EditText

For editext providing options for bold italic underline you can always use Spannable to achieve it

// Get our EditText object.
EditText vw = (EditText)findViewById(R.id.text);

// Set the EditText's 
text.vw.setText("Italic, highlighted, bold.");

// If this were just a TextView, we could do:
// vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE);
// to force it to use Spannable storage so styles can be attached.
// Or we could specify that in the XML.
// Get the EditText's internal text storage

Spannable str = vw.getText();

// Create our span sections, and assign a format to each.

str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

The details you can find here

http://developer.android.com/resources/faq/commontasks.html#selectingtext

like image 146
Deva Avatar answered Apr 16 '26 06:04

Deva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!