Is it possible to change the single textView size dynamically?
In the below link the text size is dynamically changed. ? can anyone guide me on how to do this. thanks in advance
Thanks for all, at-last i used three different textview to design whatever i need. Thanks for all.
Yes. You can use SpannableStringBuilder to styling the text.
Same question is registered at here
Try following code
span.setSpan(new RelativeSizeSpan(0.8f), start, end,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Here, you need to set start and end as per your requirement. 0.8f is size of text here. You need to pass float value here.
Code
textView = (TextView) findViewById(R.id.textView);
Spannable span = new SpannableString(textView.getText());
span.setSpan(new RelativeSizeSpan(0.8f), 0, 7,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new RelativeSizeSpan(1.8f), 7,
txt.getText().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
txt.setText(span);
Output
Related
This is what I have done!
spannableString.setSpan(new BackgroundColorSpan(ContextCompat.getColor(mContext, R.color.highlightColor)), 0, div.getText().length(), 0);
textview.setText(spannableString);
Result Achieved!
Desire Result!
Maybe this link can help you: Can I select a color for each text line I append to a TextView?
But instead of the ForegroundColorSpan try using the BackgroundColorSpan
[I want to change edit text color when character limit exceeds just like in this image.]
[[1]: http://i.stack.imgur.com/fHTCA.png]
How to give this effect on Text Change Listener ???
I'd suggest following this link, which I believe show you how.
Android: Different colours for different characters in EditText
You can use Spannable :
EditText tv = (EditText )findViewById(R.id.tv);
Spannable wordtoSpan = new SpannableString("I know just how to whisper, And I know just how to cry,I know just where to find the answers");
wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
wordtoSpan.setSpan(new ForegroundColorSpan(Color.RED), 5, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(wordtoSpan);
Or html format Html.fromHtml :
String text = "This is <font color='red'>red</font>. This is <font color='blue'>blue</font>.";
tv.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);
try This I think this will help you:
if(edit_text.length> limit){edit_text.settextcolor("your color code");}
I need to add multiple styles for text in my edittext, after searching I have found two ways
1- using this and it is working for me
str.setSpan(new BackgroundColorSpan(getResources().getColor(R.color.correct_email_color)), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
2- using HTML format, and I need to be able to use this to add padding and margin to my text :
str.setSpan(new SpannableString(Html.fromHtml(String.format(EMAIL_HTML_FORMAT, "ffA9F5BC" , splittedEmail[i]))), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
but the second way is not working, can any one help here ??
Not sure but I think you have to use
android.text.style.LeadingMarginSpan
For e.g:-
str.setSpan(new android.text.style.LeadingMarginSpan.Standard(30, 0), 0, s.length(), 0);
Look into the following..http://developer.android.com/reference/android/text/style/LeadingMarginSpan.html
Hope this will helps you.
String text = "<body>By clicking Sign Up i agree with Facebook<b>Terms and Conditions</b> and <b>Privacy Policy</b></body>";
Spanned spanned1 = Html.fromHtml(text);
tvTerms.setText(spanned1);
above code is just snippest to use style through html tag hope it wll help you to achieve your requirement that how to give style through html tag in android
I have TextView and I want each word of the text to be with different size and font.
I know that you can set part of the text to be bold or with underline with the and tags.
But what if I need part of the text to be the size of 18sp and have a custom typeface(from assets) and another part to have a different custom typeface and a size of 14sp.
I can split the TextView to individual TextViews, but I want to avoid that.
You should use RelativeSizeSpan ,for Reference RelativeSizeSpan for different font sizes.
TextView tv;
final SpannableString text = new SpannableString("Hello World");
text.setSpan(new RelativeSizeSpan(2.0f), 0, 5,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new RelativeSizeSpan(1.5f), 5, 11,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(text);
For FontStyle use StyleSpan for reference StyleSpan
So use can use custom typeface with the help of StyleSpan.
text.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), start,
end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
Hope this will help you.
You can write your code in HTML with all the styling you like and then use Html.fromHtml() in the setText() method:
E.g.:
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
Or:
Refer to this question. it might help you:
Custom Textview with Html text and Custom Font whole Android application
Is it possible to have texts with different sizes, font-types or styles in the same TextView ?
Something like this:
| myLogin logout |
You can do this using:
textView.setText(Html.fromHtml("<b>myLogin</b> <i>logout</i>"));
For more options, look into SpannableString: Link
With SpannableString, you can apply multiple formatting to a single string.
This article will be very helpful to you: Rich-Style Formatting of an Android TextView
For anyone who wants to do this without the HTML formatting , use a SpannableString.
As in :
SpannableString styledString = new SpannableString("myLogin logout");
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, 7, 0);
styledString.setSpan(new StyleSpan(Typeface.ITALIC), 8, 14, 0);
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText(styledString);
More examples can be found here
Unless you make a custom TextView, no. Consider using two different TextViews if you do not want to create a custom TextView.