Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: EditText with syntax highlighting

How to make EditText with syntax highlighting? There are ready solutions? HTML tags to insert as it seems to me, is not the best option, the app will slow down.

like image 257
gc986 Avatar asked Sep 11 '26 12:09

gc986


1 Answers

  editText.addTextChangedListener(new TextWatcher() {
    final String FUNCTION = "function";
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {} 

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {}

    @Override
    public void afterTextChanged(Editable s) {
        int index = s.toString().indexOf(FUNCTION);
        if (index >= 0) {
            s.setSpan(
                    new ForegroundColorSpan(Color.CYAN),
                    index,
                    index + FUNCTION.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
});

Refered from

like image 140
Dishant Anand Avatar answered Sep 13 '26 02:09

Dishant Anand



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!