I do something similar to a text editor. It is necessary to implement text formatting (bold, italic, underline). Can be selected as one component or all at once. The style should be applied to all text in editText. The server is waiting for me Html.

I made a popupMenu in which the points are bold, italic and underlined. How do I implement the formation of html by clicking on the menu items?

PS tried to shove html tags into resources, but the studio does not perceive tags in resources. also tried through TextWatcher but did not succeed (

Closed due to the fact that the issue is too common for participants Denis Bubnov , AK , user194374, fori1ton , Akina 8 Feb '17 at 8:08 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    Create three variables

    boolean boldEnabled, italicEnabled, underlineEnabled; 

    Create three buttons for switching text modes and in the listener implement the trigger logic, for example, for the bold text button

     boldEnabled = !boldEnabled; 

    Create a method to update text modes.

     public void refresh() { editText.setTypeface(null, Typeface.NORMAL); if(boldEnabled && italicEnabled) editText.setTypeface(null, Typeface.BOLD_ITALIC); else if(boldEnabled) editText.setTypeface(null, Typeface.BOLD); else editText.setTypeface(null, Typeface.ITALIC); if(underlineEnabled) edittext.setPaintFlags(editText.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG); } 

    And call this method in all three listeners of buttons-triggers.