Make text colored inside EditText - java

Can I somehow color the text inside EditText without using Spannable?
I will be glad to any link.
Now I use Regex for search keywords and dynamically color the text inside EditText. (I use Kotlin coroutines)
Editable.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
But when I open the text from large Text file 600+ lines, my UI starts to slow down.

Related

Android get focused word from edittext

Lets say I have an Android edittext with sentence: "I like Stackoverflow very much". Then I use my keyboard to be focused on the word Stackoverflow and now I click the button in my app that adds / removes for example bold effect for this specific word.
Is it possible to do that?
Thank you in advance.
if you are talking about position of cursor then use
int cursorPosition = et.getSelectionStart();
after taking position of cursor you should take whole text and apply desired effect. for example split text by white characters (spaces, enters), calculate on which word cursor is pointing and add/remove bold spannable
note that et.getText() returns Editable, not just usual String. So you can do some work on this class, e.g. check if word with cursor inside is already bold or other spannable applied

How can I make any selected text in an EditText Bold or Italic in android studio and store it into a SQLite database?

How can I make any selected text in an EditText Bold or Italic in android studio and store it into a SQLite database?
First make a class to get the start and end position of the selected text.
And a style variable for storing bold, italic or underline
class typefaces{
int style,start,end;
}
Then store the variable of the edittext in the database
start = edittext.selectionstart();
end = edittext.selectionend();
dbhelper.insertTypes(style,start,end);
add the values to the database and retrieve to again show the saved.
Use spans to add bold, italics and underline types

How to achieve an dashed EditText in Android where color of dash changes as input is taken

I'm trying to achieve the following:
Here, with every input the color of dash changes and the number of dashes is also equal to the maxLength of the EditText.
How do I achieve this in Android?
You can use material-code-input library to achieve a dashed EditText.

How to remove text from textflow in javafx?

I'm new to javafx and am trying to display large amount of text in textflow. It displays fine, but I just cannot figure out how to delete the text.
So what I'm trying to do is delete all Text nodes from textFlow like so
textFlow.getChildren().removeAll();
But when I do this and add something to textFlow, it shows after the text that was already displayed there. I would like the text that was there removed and show the added text from the beginning of the textflow.
I guess I have to somehow rerender the view of textflow, but I don't know how. So how do I delete everything and add Text anew?
removeAll(...) will remove all the values you pass as parameters: in your case there are none, so it doesn't remove anything. Use
textFlow.getChildren().clear();

Java Swt Text (SWT.MULTI) append text without scroll

I have a Java SWT GUI with a multiline Text control. I want to append lines of text to the Text control without affecting the position of the cursor within the text box. In particular, the user should be able to scroll and select text at the top of the Text control while new text lines are appended to the bottom.
Is this possible?
I switched to using a StyleText control to fix flickering issues when adding text. With this control I found the following code fixed the issue of appending text without scrolling to the new location.
textOutput.setRedraw(false);
int scrollP = textOutput.getTopIndex();
Point selectionP = textOutput.getSelection();
textOutput.append(traceText);
textOutput.setSelection(selectionP);
textOutput.setTopIndex(scrollP);
textOutput.setRedraw(true);

Categories