How to set the color of a text in TextField for Harmony OS? - huawei-mobile-services

How to set the color of a text in TextField? For example, set the "Harmony" font in the "Hello Harmony" field to red The Android code is implemented as follows:
SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.setSpan(new ForegroundColorSpan(getCurrentHintTextColor()), i, i + 1, 0);

Can use RichText for Harmony OS, you can achieve the same effect. Please see below screenshot for the sample code, which will set Harmony to red.
Text text = ComponentHelper.getShapeText( context: this);
text.setTextSize(80);
RichTextBuilder builder = new RichTextBuilder);
TextForm redForm = new TextForm();
redForm.setTextColor(Color.RED.getValue(0);
redForm.setTextSize(50);
builder.mergeForm(redForm);
builder.addText("Harmony");
TextForm blackForm = new TextForm();
blackForm.setTextColor (Color.BLACK.getValue ());
blackForm.setTextSize(60);
builder.mergeForm(blackForm);
builder.addText("OS");
text.setRichText(builder.build());
RichTextBuilder and TextForm Links are below:
https://developer.harmonyos.com/en/docs/documentation/doc-references/richtextbuilder-0000001054358740
https://developer.harmonyos.com/en/docs/documentation/doc-references/textform-0000001054120081

Related

character coloring in just one textspan according to index in Flutter

I want apply different color to character in a textspan in Flutter.
I know Rich Text and TextSpan method but adding TextSpan every part of text that has different color, is not available for my problem, it causes slipping on Harakas of Arabic
I would like solve this like Android Spannable String index of text.
Is possible in Flutter?
like this
SpannableString ss = new SpannableString(st);
ss.setSpan(new ForegroundColorSpan(Color.GREEN), 11,25, 0);
If i understand your question correctly i would say use Ternary operators
SpannableString ss = new SpannableString(st);
ss.setSpan(index == foo ? <Other option here> : new ForegroundColorSpan(Color.GREEN), 11,25, 0 );

C# How can I Coppy All Things in RichTextBox?

I have a richTextBox and I add text and image. Text are not the same color and font. I want to convert to all things for doc file. I am using this codes for this.
wordeaktar.Application wordapp = new wordeaktar.Application();
wordapp.Visible = true;
wordeaktar.Document worddoc;
object wordobj = System.Reflection.Missing.Value;
worddoc = wordapp.Documents.Add(ref wordobj);
wordapp.Selection.TypeText(richTextBox1.Text);
wordapp = null;
enter image description here
This is the image of my richTextBox. How can I do that?
#Gserg's Answer is right!
"richTextBox1.SelectAll(); richTextBox1.Copy(); worddoc.Range().Paste();. However if you simply richTextBox1.SaveFile("...", RichTextBoxStreamType.RichText), Word will be perfectly happy with that. – GSerg"

Changing colours for button which have got a focus

I use DotNetBar controls. I can change colours for buttons with:
Office2007ColorTable table = ((Office2007Renderer)GlobalManager.Renderer).ColorTable;
Office2007ButtonItemColorTable bt = table.ButtonItemColors[6];
bt.Default.Background = new LinearGradientColorTable(Color.White);
bt.MouseOver.Background = new LinearGradientColorTable(Color.Green);
Unfortunate I cannot find how I can change colour for a focused button.
Is it possible?

Label on HeaderIcon in HeaderControls

I want to put a label next to an icon so user can better understand what is this clickable icon for.
This icon appear in the HeaderControl of a com.smartgwt.client.widgets.Window
String promptNewThing = "Add some thing";
String imgNewThingText = "../servlet/servletOperation?cmd=Icon&time=" + System.currentTimeMillis() + "&text=" + promptNewThing;
HeaderIcon iconNewThing = new HeaderIcon("buttons/new.png");
HeaderIcon iconNewThingLabel = new HeaderIcon(imgNewThingText);
newThing = new HeaderControl(iconNewThing, clickHandlerNewThing);
newThing.setPrompt(promptNewThing);
newThingLabel = new HeaderControl(iconNewThingLabel, clickHandlerNewThing);
newThingLabel.setPrompt(promptNewThing);
setHeaderControls(HeaderControls.HEADER_LABEL, NewThing, NewThingLabel, HeaderControls.MINIMIZE_BUTTON, HeaderControls.MAXIMIZE_BUTTON, HeaderControls.CLOSE_BUTTON);
For information : In this code, Servlet URL return an image made from the text promptNewThing
But iconNewThingLabel is an Icon which has the width of an Icon, too small.
The result of this code :
The small white square we can see between first Icon is newThingLabel.
Is there a way to add a label at the right of an HeaderIcon ?
For example I would to have something like :
Hello Manu I have done the same thing as you have done. The only change is instead of adding HeaderIcon (iconNewThingLabel in your case - if it's representing the text), I have used a com.smartgwt.client.widgets.Label & added that as a headerControl. Code snippet is as follows:
Label label = new Label("test header");
setHeaderControls(HeaderControls.HEADER_LABEL, NewThing, label, HeaderControls.MINIMIZE_BUTTON, HeaderControls.MAXIMIZE_BUTTON, HeaderControls.CLOSE_BUTTON);
Let me know if this helps you.

Hiding cursor in Text component in Eclipse RCP application

In my eclipse RCP application there are a few buttons & few input boxes & this below Text component. My problem is as soon as I press one of the buttons a cursor starts blinking in the below test component. Can you please let me know how to solve this.
I tried:
setting focus to false for Text.
SWT.READ_ONLY for Text .
Code:
Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_NO);
protocolFilterDescription.setCursor(cursor);
Nothing seems to get rid of this unnecessary cursor.
protocolFilterDescription = new Text(parent, SWT.NONE | SWT.READ_ONLY );
FormData protocolFilterDescriptionLData = new FormData();
protocolFilterDescriptionLData.left = new FormAttachment(0, 1000, 650);
protocolFilterDescriptionLData.top = new FormAttachment(0, 1000, 290);
protocolFilterDescriptionLData.width = 450;
protocolFilterDescriptionLData.height = 12;
protocolFilterDescription.setLayoutData(protocolFilterDescriptionLData);
protocolFilterDescription.setForeground(new Color(parent.getDisplay(),
204, 153, 0));
protocolFilterDescription.setBackground(Display.getCurrent()
.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
protocolFilterDescription.setFont(new Font(parent.getDisplay(),"Verdana",
6, 1));
protocolFilterDescription
.setText("captured");
You have to set the focus of some other SWT component to true to remove the focus from the Text component.
You'll probably have to do this in an ActionListener.
If you want to completely remove the cursor from the Text control (which implies inability to perform a selection there, etc), try calling setEnabled(false) on it.
Also, such requirement suggests that you maybe don't need Text component at all, and could use Label instead.