How can I set an EditText to have italic hint text? - android-widget

How can I set the hint text of an EditText to be italic in Android?

EditText.setText("");
EditText.setHint("hint");
EditText.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
....
EditText.setText("text");
EditText.setTypeface(Typeface.MONOSPACE, Typeface.NORMAL);

To set text as italic, you can do the following:
EditText.setText(Html.fromHtml("<small><i>" + "Text Hint Here" + "</i></small>"));
If you would like the italic text to be a hint - when the EditText is empty for example - you must implement a method to check the text length, and when it is equal to zero, apply the above code.

You can do everything in XML.
First declare your hint in the "strings.xml" file. Your define it to be italic by using the "< i >" tag
<string name="EditBoxHint"><i>Whatever you want to show</i></string>
Finally, in the layout declaration you add your hint referencing this previously declared string.
<EditText
...
android:hint="#string/EditBoxHint"
...
/>

Related

How can I get text value of TMPro Text without markup tags in Unity?

I am trying to get text value in TMPro Text component without markup tags but haven't found any solutions.
Say, <b><color=red>Hello </color><b> world is the value in TMPro Text, and I just want Hello world in c# script.
Bear in mind that tag <b> and color will change, so I would love to remove tags dynamically, meaning I would like not to replacing each tag by text.replace("<b>", "") kind of things.
Does anyone know how to do it?
I dont know about the option of using HTML on tmp but you can attach the text to your script by create a new variable like that:
[SerializeField] TMP_Text textVar;
then you can drag you tmp game object to the component that include this script
and the you can change the text like that:
textVar.text = "what ever";
or get text like that:
string textString = textVar.text;
for the color you can use
Color color = textVar.color;
You can use TMP_Text.GetParsedText () to get the text after it has been parsed and rich text tags removed.
Alternatively you can also use regular expressions to search a string for rich text tags, and remove them while preserving the rest of the string.
using System.Text.RegularExpressions;
public static string GetString (string str)
{
Regex rich = new Regex (#"<[^>]*>");
if (rich.IsMatch (str))
{
str = rich.Replace (str, string.Empty);
}
return str;
}

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 );

Add Placeholder to UITextField, how to set the placeholder text programmatically in swift?

I'm pulling out a phone number from a database, and when the user begins editing in the text field to change that phone number I'd like to use the number I currently have in the database as the placeholder. Since this information changes with each user, how can I set it programmatically in swift?
You need to get the phone number from your database first (convert them to String), then you set placeholder of your textField to that String, like so
textField.placeholder = phoneNumberString
Swift 3
If your textField has text, you need to first set text property to nil, then set placeholder text:
textField.text = nil
textField.placeholder = "My Placeholder Text"
Important to note for anyone else reading this, setting placeholder text in the main.storyboard seems to nullify this solution, so I had to first clear out my placeholders in the storyboard before implementing this. Once that was done #Khuong and #Himanshu's answer worked perfectly.
Apply this line of code in to View Did Load
new_Password.attributedPlaceholder =
NSAttributedString(string: " New Password", attributes: [NSForegroundColorAttributeName : UIColor.white]) // new_Password : our text feild name
Fetch your desired data from your database (Core data) and after converting it into string format... say phoneString
use this line to set this string as a placeholder text
phoneTextField.placeholder = phoneString
Objective-C code:
[usernameText setPlaceholder:#"My Placeholder Text"];
Just a note to say if you have changed your textfield's text and background colors programmatically, you can't do that with the placeholder text's colors and must set up an Attributed Placeholder instead. This is a problem if your device is in put in "dark mode" and are trying to make a non-dark mode screen by hand - you might not be able to see the placeholder!

How to set text position to bottom in textField

I created a textField through code using the following code
UITextField *txtObj=[UITextField alloc]initWithFrame:CGRectMake(88,100,80,33)];
I am getting the textfield as i planned, but the text we type in that text field seems to appear in the top area of text but not in bottom.I tried to align it but i got tired. Can anyone tell me what's the solution
it should be:
txtObj.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
This property is inherited from the UIControl class. The default is: UIControlContentVerticalAlignmentTop , that's why you get the text on top.
txtObj.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
If you want the text to be in the center you can use ,
txtObj.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
Swift 4,5 solution:
txtObj.contentVerticalAlignment = .bottom

Gtk Button inner-border

I add a button to HBox, with expand equal to False, but I want the button to have more spacing between its label and border. I assume it is "inner-border" property, but it is read-only. How can I set it to e.g. 4px?
gtk.Label is a subclass of gtk.Misc which has the method set_padding. If you get the label out of the gtk.Button then you can just call set_padding on it.
You could do something like:
label = gtk.Label("Hello World")
button = gtk.Button()
/* Add 10 pixels border around the label */
label.set_padding(10, 10)
/* Add the label to the button */
button.add(label)
/* Show the label as the button will assume it is already shown */
label.show()
Wrong answer:
What you're looking for is called "padding". When you add your button to the container, for example by calling gtk.Box.pack_start, just set the padding parameter to a positive integer.
Update:
Seems I misread the question. In that case, my guess is that you're supposed to use gtk_widget_modify_style, as inner-border is a style property. You'll first get the style modifier you need by calling gtk_widget_get_modifier_style. You'll then be able to modify the style only for that button using the ressource styles matching rules.
you can use "inner-border" style property of gtk button.
here, small code snippets
In gtkrc file:
style "button_style"
{
GtkButton::inner-border = {10,10,10,10}
}
class "GtkButton" style "button_style"
In .py file:
gtk.rc_parse(rc_file_path + rc_file)
[Edit]
In gtkrc file:
style "button_style"
{
GtkButton::inner-border = {10,10,10,10}
}
widget "*.StyleButton" style "button_style" # apply style for specific name of widget
In .py file:
gtk.rc_parse(rc_file_path + rc_file)
#set name of button
self.style_button.set_name('StyleButton')
hope, it would be helpful.
I sometimes just add spaces in the label !
gtk.Button(" Label ")
to get some spacing.
Hope this could help you.