Underlined text on Android Canvas

How to draw underlined text on canvas using Android? I know how Bold and Italic work, but how would I draw the text that is underlined? Is this possible, or do I need to find a workaround to fix this issue?

+3


source to share


2 answers


You can use Paint. UNDERLINE_TEXT_FLAG ,

Example:



class SampleView extends View {
        public SampleView(Context context) {
            super(context);
        }

        @Override
        protected void onDraw(Canvas canvas) {

            Paint paint = new Paint();
            paint.setTextSize(25);
            paint.setColor(Color.RED);

            paint.setFlags(Paint. UNDERLINE_TEXT_FLAG);
            paint.setColor(Color.GREEN);
            canvas.drawText("My Underline Text", 50, 140, paint);

        }
    }

      

+3


source


On the paint object, set the flag to underline the text



 paint.setFlags(Paint.UNDERLINE_TEXT_FLAG);

      

+2


source







All Articles