I am using BulletSpan(BulletSpan.STANDARD_GAP_WIDTH)
How can I change its icon from a circle to ✓?
SpannableString s = new SpannableString(text+"\n");
s.setSpan(new BulletSpan(BulletSpan.STANDARD_GAP_WIDTH), 0, text.length(), 0);
I was also trying to style the bullet icon used by Android but didn't find any answers online. I ended up using an alternative approach which may help you further as well.
I didn't use BulletSpan but I used LeadingMarginSpan instead. You can add whatever character you want as icon (such as your tick character) in the text to be "spanned". By setting the first line margin and rest margins correctly you can achieve the same effect as the BulletSpan.
Related
Is there a general method for handling font like, if it is Chinese I use a custom font for it, if English then I fall back to the default font? Thanks.
Here is my 2 cents. You can use Calligraphy library to change the custom font easily either for whole app or for specific TextView as well.
If you want to do it for whole app, then one solution I can think of is:
In your app you can listen to the Broadcast of ACTION_LOCALE_CHANGED.
Inside the listener check to see whether the locale is Locale.SIMPLIFIED_CHINESE or Locale.TRADITIONAL_CHINESE, then change the app's font.
If you want to programatically change font of lets say partial text then you can use CalligraphyTypefaceSpan as mentioned Multiple Typeface's per TextView / Spannables section:
SpannableStringBuilder sBuilder = new SpannableStringBuilder();
sBuilder.append("Hello!") // Bold this
.append("I use Calligraphy"); // Default TextView font.
// Create the Typeface you want to apply to certain text
CalligraphyTypefaceSpan typefaceSpan = new
CalligraphyTypefaceSpan(TypefaceUtils.load(getAssets(), "fonts/Roboto-Bold.ttf"));
// Apply typeface to the Spannable 0 - 6 "Hello!" This can of course by dynamic.
sBuilder.setSpan(typefaceSpan, 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
setText(sBuilder, TextView.BufferType.SPANNABLE);
Hope it helps.
P.S: I am not affiliated to the library in any way. I am a happy user of it.
I've searched something around here but nothing came up.
I'd like to have an EditText in which I can change attributes like color or dimension of a selected part.
I've already tried with the spannable thing, from another question:
TextView myTV = (TextView)findViewById(R.id.test);
String textString = "StackOverFlow Rocks!!!";
Spannable spanText = Spannable.Factory.getInstance().newSpannable(textString);
spanText.setSpan(new BackgroundColorSpan(0xFFFFFF00), 14, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myTV.setText(spanText);
I assume that I have to assign it to some onClick method..Also my problems are those two number, I should put some "selectedText" there instead I think.
Is this even possible?
I'd like to have an EditText in which I can change attributes like color or dimension of a selected part
If you want the user to "change attributes... of a selected part", my recently-updated RichEditText offers that. I do not have color or text size going yet, though, as those will need a toolbar (rather than my current action mode support).
Also my problems are those two number, I should put some "selectedText" there instead I think
You are probably looking for getSelectionStart() and getSelectionEnd().
I want to add small upper text in android textView
how would you implement this?
two textViews both layout_below the same element and then
make the second smaller?
or is there a way in one textView to put style to one word
(can be longer or shorter in other languages)?
You can achieve that by following code
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("2580<sup>TH</sup>"));
Solution from Android Layout framework, would put two textViews in side a Linear layout and that is it.
Another way, is making the small text as an image. Than you can add it to text view directly.
you can do it like this:
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("YourRank:250<sup>TH</sup>"));
also you can do it like this:
String str=getString(R.string.rank); //YourRank:250
String str2=getString(R.string.superScript); //TH
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("+str+"<sup>"+str2+"</sup>"));
it worked like charm!
You can use SpannableStringBuilder as fallows:
String text = "YourRank:250TH";
SpannableStringBuilder spannableString = new SpannableStringBuilder(text);
spannableString.setSpan(new SuperscriptSpan(), text.length() - 1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
YourTextView.setText(spannableString);
I have an Edit text field and set his inputType to "textPassword".
The default view shows little dot icons. I would like to increase their size. I assume that there's no "largeTextPassword" option and you should set this up yourself.
I made a new large dot icon and would like to place it in instead of the regular one. Now I use the setText() method to insert the text into it. How do I combine between those values?
I'v tried to increase the textSize but the padding drove me crazy on different screen sizes.
I'v tried to use the setCompoundDrawablesWithIntrinsicBounds(R.drawable.dot, 0, 0, 0) method but still, I'm not sure this the right way.
If someone can shed some light on this would be great.
Don't use android:inputType="textPassword" because this will replace the characters with the default dot character.
Add a TextWatcher and, as the user types, store/append the new character in/to a String and replace that character in the EditText with an ImageSpan of your own.
I can't seem to figure out a way to easily display a fraction in a textview. Let be more clear i need a fraction with a number over a number in a textview and then there should be able to add more text after that all in the same textview. I have seen this linke Android - displaying fractions using unicode
And the solution does not work great especially when playing it into a alertdialog the formating is lost.
I have also tried this
SpannableStringBuilder test = new SpannableStringBuilder();
SpannableString content = new SpannableString("3");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
test.append(content);
test.append("\n");
test.append("56");
This works great however if I need to add more to that line it will be displayed on the bottom and i need it on the top line. If i try to insert into the top line then the bottom line will move because the textview is centered (also it wont work by aligning the text view in any particular way since i may have text before the fraction).. *I do not want multiple textview
The solution was to use this html format from the link. However you must add a extra space on the top and bottom to keep it from being cut off.
SpannableStringBuilder test = new SpannableStringBuilder();
test.append("\n");
test.append(Html.fromHtml("<sup>5</sup>/<sub>9</sub>"));
test.append("\n");