Android How to get selected word in Edittext?

前端 未结 2 409
星月不相逢
星月不相逢 2021-01-18 08:58

I am developing an app like Notepad in which I want to change the selected text formatting dynamically (colors, changing font styles, bold, italic, underline etc.) How can I

2条回答
  •  被撕碎了的回忆
    2021-01-18 09:19

    EditText et1=(EditText)findViewById(R.id.edit);
    
    int startSelection=et.getSelectionStart();
    int endSelection=et.getSelectionEnd();
    
    String selectedText = et1.getText().substring(startSelection, endSelection);
    

    Hope this code suits yours case

提交回复
热议问题