re-setting a TextView height programmatically

You should change it via LayoutParams: LayoutParams params = (LayoutParams) textView.getLayoutParams(); params.height = 70; textView.setLayoutParams(params); EDIT You should not use sizes in pixels in you code, use dimensions for this: dimens.xml: <dimen name=”text_view_height”>50dp</dimen> In code: params.height = getResources().getDimensionPixelSize(R.dimen.text_view_height);

textview.getLineCount always 0 in android

I know this question is quite old, but in case anyone comes here looking for the actual answer: holder.text2.setText(arr2[position]); holder.text2.post(new Runnable() { @Override public void run() { int lineCnt = holder.text2.getLineCount(); // Perform any actions you want based on the line count here. } });

Custom cut/copy action bar for EditText that shows text selection handles

I figured out the answer to my own question; TextView (and therefore EditText) has a method setCustomSelectionActionModeCallback() which should be used instead of startActionMode(). Using this enables customisation of the menu used by TextView for text selection. Sample code: bodyView.setCustomSelectionActionModeCallback(new StyleCallback()); where StyleCallback customises the text selection menu by removing Select All and adding some …

Read more

Android SpannableString set background behind part of text

If anyone’s having difficulty with Roosevelt’s code sample (I sure was, maybe because it’s Xamarin.Android?), here’s a translation into a more basic Android java version: public class RoundedBackgroundSpan extends ReplacementSpan { private static int CORNER_RADIUS = 8; private int backgroundColor = 0; private int textColor = 0; public RoundedBackgroundSpan(Context context) { super(); backgroundColor = context.getResources().getColor(R.color.gray); …

Read more

Extra padding on TextView with HTML contents

The extra ‘padding’ you’re seeing, is in fact just a line break followed by another line break: When you dive into the Html.fromHtml(…) implementation, you’ll come across the following method that handles paragraph tags: private static void handleP(SpannableStringBuilder text) { int len = text.length(); if (len >= 1 && text.charAt(len – 1) == ‘\n’) { …

Read more

How to implement increasing number animation from 0 to 600 in 5 secs on TextVIew on android

You could use the ValueAnimator for that: private void startCountAnimation() { ValueAnimator animator = ValueAnimator.ofInt(0, 600); animator.setDuration(5000); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { textView.setText(animation.getAnimatedValue().toString()); } }); animator.start(); }

how to get text from textview

I haven’t tested this – but it should give you a general idea of the direction you need to take. For this to work, I’m going to assume a few things about the text of the TextView: The TextView consists of lines delimited with “\n”. The first line will not include an operator (+, -, …

Read more

Setting Ellipsize on TextView reduces lines shown by one (instead of only ellipsizing last)

This is by far the simplest solution I’ve found and am currently using in deployment. Let me know if you need any other assistance! Oh and remember to remove the android:ellipsize tag in your XML since you will be using the bottom code to automatically ellipsize at the end of 3 lines. TextView snippet; snippet.setText(“loren …

Read more