Question

I am working with an EditText to support the properties of bold, italic, and underline. I was successful after selecting the text and clicking on a button to bold my text.

Now I want to remove the bold again after selecting the text and clicking on bold button.

It is simply not setting the flag to do bold and remove the bold. I have to know the text we have selected is in bold and if it is bold then we have to remove the bold by clicking the same button. Need this text editor to support from version 2.3.

Any help would be greatly appreciated. Thanks:)

No correct solution

OTHER TIPS

The code below offers a beginning to understanding how to extend the EditText class. What this code does is draw a line under each line of words. This does not offer rtf, however.

public class LinedEditText extends EditText {
    private Rect mRect;
    private Paint mPaint;

    // we need this constructor for LayoutInflater
    public LinedEditText(Context context, AttributeSet attrs) {
        super(context, attrs);

        mRect = new Rect();
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);

        // set your own color here, referencing color resource file
        int color = ContextCompat.getColor(context, R.color.edit_note_line);
        mPaint.setColor(color);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //int count = getLineCount();

        int height = getHeight();
        int line_height = getLineHeight();

        int count = height / line_height;

        if (getLineCount() > count)
            count = getLineCount();//for long text with scrolling

        Rect r = mRect;
        Paint paint = mPaint;
        int baseline = getLineBounds(0, r);//first line

        for (int i = 0; i < count; i++) {

            canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
            baseline += getLineHeight();//next line
        }

        super.onDraw(canvas);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top