spannablestring

SpannableString changes color first time, but not when reused

冷暖自知 提交于 2019-12-10 10:23:49
问题 I'm trying to make a game to help kids learn math. I color code numbers so they can follow the logic. I also use textView.append() to build a long string to put into the activity. Because I re-use the same numbers/symbols in instruction, I wanted a way to easily recycle the SpannableStrings, but it seems that the changes I make are applied correctly the first time, but thereafter sometimes work, sometimes partially work (e.g. right size/alignment, but wrong color), or don't work at all. I'm

Using custom font for part of a Text

只谈情不闲聊 提交于 2019-12-10 10:15:53
问题 Typeface robotoBold = Typeface.createFromAsset(activity.getAssets(), "fonts/Roboto-Bold.ttf"); Typeface robotoLight = Typeface.createFromAsset(activity.getAssets(), "fonts/Roboto-Light.ttf"); SpannableStringBuilder sb = new SpannableStringBuilder("This must be BOLd\nThis must be NORMAL"); sb.setSpan(robotoBold, 0, 17, Spannable.SPAN_INCLUSIVE_INCLUSIVE); sb.setSpan(robotoLight, 18, 37, Spannable.SPAN_INCLUSIVE_INCLUSIVE); mTextView.setText(sb); This gives me a normal text for the whole

How to add red wavy line below text in Android's TextView

╄→尐↘猪︶ㄣ 提交于 2019-12-09 19:38:31
问题 I'm trying to add red wavy line below errors in texts, such as: Unfortunately I can't find a proper *Span class to wrap the error text with. How should I implement such a feature in Android? 回答1: I've solved the problem by implementing a custom Span: Add error_underline.png to your resources: <-- tiny 6x3 pixels here Then use this class to create spans: static class ErrorSpan extends DynamicDrawableSpan { private BitmapDrawable mRedWavy; private int mWidth; private int mBmpHeight; ErrorSpan

Android - Add Margin for SpannableStringBuilder using ReplacementSpan

时间秒杀一切 提交于 2019-12-09 13:17:45
问题 I'm trying to format Hashtags inside a TextView/EditText (Say like Chips mentioned in the Material Design Specs). I'm able to format the background using ReplacementSpan . But the problem is that I'm not able to increase the line spacing in the TextView/EditText. See the image below The question is how do I add top and bottom margin for the hashtags? Here is the code where I add the background to the text: /** * First draw a rectangle * Then draw text on top */ @Override public void draw

How to alpha / translate animate each word in a TextView instead of each character?

半城伤御伤魂 提交于 2019-12-09 11:10:54
问题 I am working with the following Spannable and TextView like so and I've got it animating each character but I want to animate each word how can I accomplish that? Looking to alpha in and translate each word (from the bottom of the location of each word). By translating I mean a translate (move) animation. Source: private static class FadeyTextView extends TextView { private Interpolator mInterpolator; private long mStart, mDurationPerLetter; private boolean mAnimating = false; private

Android点击获取验证码60秒后重新获取验证码

情到浓时终转凉″ 提交于 2019-12-09 10:12:58
这几天跟验证码干上了,我最开始的思路是开启一个线程然后计算倒计时,后来经同事开导,觉得那样的做法low逼到家了. 上代码 /** * Created by Xia_焱 on 2017/5/7. */ public class CountDownTimerUtils extends CountDownTimer { private TextView mTextView; /** * @param millisInFuture The number of millis in the future from the call * to {@link #start()} until the countdown is done and {@link #onFinish()} * is called. * @param countDownInterval The interval along the way to receive * {@link #onTick(long)} callbacks. */ public CountDownTimerUtils (TextView textView, long millisInFuture, long countDownInterval) { super (millisInFuture, countDownInterval); this

Paragraph spacings using SpannableStringBuilder in TextView

吃可爱长大的小学妹 提交于 2019-12-08 23:56:36
问题 As the question indicates, I am working on a TextView which will show formatted text using SpannableStringBuilder . It has multiple paragraphs and I would like to know what would be the easiest (or at least the least complicated) way to set spacing between paragraphs using some inbuilt span. Is this possible? Or will I be required to build a custom span class for this? 回答1: Implement the LineHeightSpan and override chooseHeight method as follows @Override public void chooseHeight(CharSequence

Android EditText: how to apply spans when composing?

对着背影说爱祢 提交于 2019-12-08 19:38:29
How can I apply spans on EditText text when the user is composing? For example the user has activated "bold" when composing, so every character input since then should be bold . I thought about adding text change listener to the EditText and update the text as the user composes, but I wanna know if there's a better way of doing this. The question was already answered in the comments, but to make it more permanent I will add a fuller answer. In order to set a span (like Bold) wherever the user is composing, you just set a span on the text at the cursor (or selection) position. StyleSpan

Android - Ellipsize & Truncate all long Urls in a Textview

蹲街弑〆低调 提交于 2019-12-08 07:53:13
问题 In my android app's textview, I want to ellipsis all URLs (which already have been linked using clickable span) to get ellipsis (or truncate) if the length of URL is greater than a certain limit. This behaviour is inspired from twitter and facebook. For example, the link http://www.getfluttr.com/flap/3rL7/now-only-if-modi-would-listen-to-opposition-party-/ it should look something like this: (Screenshot Source: Twitter) I understand that this has to involve spans. I can't seem to be able to

Android EditText: how to apply spans when composing?

非 Y 不嫁゛ 提交于 2019-12-08 04:26:14
问题 How can I apply spans on EditText text when the user is composing? For example the user has activated "bold" when composing, so every character input since then should be bold . I thought about adding text change listener to the EditText and update the text as the user composes, but I wanna know if there's a better way of doing this. 回答1: The question was already answered in the comments, but to make it more permanent I will add a fuller answer. In order to set a span (like Bold) wherever the