Changing text's size according to TextView - android

Hi guys I've wondered if I could resize the TextView's text in order to make it fit withing the text view.
I want the text view to have a default text size, but in case the text is too long and requires more text than the TextView could offer, the text size should get smaller.
I've seen this answer which is awesome, but it's also from 2013, so I've wondered if there's a simpler way of doing this. Android keeps changing and evolving so I just wanted to make sure there's no easier solution first.

You can use AutoFitTextView for better result .
A TextView that automatically fit its font and line count based on its
available size and content.

There is no built-in way of achieving this in Android, so you'll have to resort to 3rd party classes and libraries to fix your problem (Like the one you linked)
I have tried a few different classes i found from googling around about 6 months ago, but i never found a 100% working solution, there were always some little kinks or flaws in my experience.

Related

Can I get and set textcolor of a textView using Accessibility in Android

I am developing an app for color-blind, I want to know if I can change the textcolor of a textView using Accessibility in Android.
Also, I would like to change the textSize using Accessibility.
Can I do these things?, If yes, how?
No, you cannot. You don't get the actual TextView of the represented text. You get access to an AccessibilityNodeInfo. The accessibility APIs don't provide this information. You could do some hacky things if you also controlled the app content, but if you want something that will work universally over all applications, you simply can't do this.
You could guess at the size of the text by checking the size of the TextView. The size of the TextView is passed to you through
aNodeInfo.getBoundsInScreen(resultBounds);
Although, this is very hacky and not reliable. The size of the view and the text size don't have to be the same, or even remotely related. Though generally for single line TextViews there will be a tight correlation. Notably, you cannot detect when a TextView is single line :)
For text size of the textview you can provide size in terms of 'sp' instead of 'dp'. Framework will automatically take care of size.
And for color above answer given by #rakesh can be one of the answers.

Letter Spacing in EditText for Android

I am trying to have a custom EditText based on the background that i am using for. The Background image has some spaces between the entry areas so i need to have some space between the characters(kerning) to fit them right in. So for example after every character the user enters, i need to put 4 whitespace after that.
I couldn't find any solution for this on the net so far, some people suggested TextWatcher, but i couldn't manage to make it work as i want it too.
Can someone help me about it?
Thanks
I have you considered using a custom font? Some font types are made to stretch out or shrink or have empty spaces. With so many different fonts available online, you can definitely find something. You can also make your own with a software. It might be time consuming if you start the lettering from scratch. I'm not 100% sure if it'll fit exactly to your background, but it's idea that you can consider.
If it doesn't fit, I supposed you can always customized the background to fix your font too. Here's the code for those who might want to use custom fonts in their app too.
Typeface myfont = Typeface.createFromAsset(getAssets(),
"fonts/Blocks2.ttf");
myeditText.setTypeface(myfont);
The font is in the asset folder under another folder called fonts.
This question is related to How to change letter spacing in a Textview?
As shown at this issue: android format edittext to display spaces after every 4 characters a solution might be to insert spaces with Java code...
You need to use TextWatcher to achieve visual purpose spaces.
And use any simply split string by space logic to join it back or loop
through the entire string per character wise and eliminate (char) 32
from the string
As far as i know actual character spacing is not possible, though i'd love to use that myself as well.
Another option might be to use a custom font with the character spacing included.

Text Fit In TextView

I have a TextView that is going to display one single sentence.
This sentence could be shorter or longer, up to 200 characters for example, but could be more.
I am trying to fit the size of the TextView dynamically according to the text that will be written, but nothing that I have found so far works for me.
I have tried the Auto Scale TextView Text to Fit within Bounds but it's not perfect for my needs as it adapts the text to a very small size and writing two lines, leaving a huge blank space on top and under the text.
EDIT: I see that in phones this solution works perfect. However, when I test in a tablet, it does not increase the text size to fill as much as possible. I am not sure, but I think it only decreases to fit. Please, correct me if I am wrong.
Has somebody tried a different solution?
You could try the AutoScale TextView third-party widget.

Android Text Display - Canvas.drawText() output pixelated

My Android app displays text in a few different ways, and there are some annoying differences between them I was hoping folks could help with.
When I use display methods that might be termed "automatic," the text is displayed very nicely. By automatic methods, I'm referring tools, like Toasts and Button widgets where I just have supply the text, and the OS (or "environment" or whatever) displays it for me. The letters are nicely curved, pleasant to look at, and easily legible.
However, in my code where I handle the text display (using Canvas.drawText() in a Surface Runner View), the text quality is poor. The text is still legible, but it looks pixelated. The letters just don't look their best.
I've tried experimenting with Paint.setTypeface(), using Typeface.SANS_SERIF for example, but the quality of the display when it's my code is always poor. Doable, but poor.
Has anybody else experienced this? By any chance does anybody have a solution?
You might also try playing around with Paint.setAntiAlias(boolean) or Paint.setSubpixelText(boolean).

Android TextView and how to determine the number of visible characters

How can I determine the number of visible characters that a TextView can display. For example if I change the orientation this number may change. If I change the resolution then also the number of visible characters changes.
Thanks in advance
Thank you for your answer.
Currently I am developing a small text based game to become acquainted with the Android API. For that reason I need to know exactly how much characters can be displayed in the visible area of a TextView widget. I saw an example of Paint but wanted to know if there are better solutions.
Ideally, you design your GUI such that it does not matter. For example, you can use android:ellipsize to deal with strings that are too long for the available space.
There are classes in the 2D drawing APIs (e.g., Paint) that seem to be tied into this, but it does not look like much fun.
You can use ellipsize property but there has been a bug that has been filed on the same
http://code.google.com/p/android/issues/detail?id=2254
On the bottom of this page you could find an alternate approach which can draw exactly the number of lines on a given space...

Categories

Resources