Getting the default font size of a multiline TextView in Android

I want to have a font-size preference in percentage relative to the default font-size, so I need to get the default font-size for a TextView.

How do I get the default font-size of a TextView?


Asked by: Chloe562 | Posted: 20-01-2022






Answer 1

This will return the value in pixels within a context:

float size = new TextView(this).getTextSize();

Answered by: Kelvin866 | Posted: 21-02-2022



Answer 2

TextView txt = (TextView) findById(R.id.text);
float size = txt.getTextSize();

This should do it on an existing one

Answered by: David555 | Posted: 21-02-2022



Similar questions

multiline textview in android

in this activity, i have two textview in first textview, the last line has only two character so it looks like some odd. so i want to check the last line of textview, and if the number of character in last line is less than 10 then i want to remove that character from line 1. so how can i get the last line characters? help me


layout - How to get maximum width of multiline TextView in android?

I am new in android and facing the problem to get the maximum width of the multiline TextView. I used textview.getWidth() and textview.getMeasuredWidth() but both gives garbage value. I used also textview.length(), but retuns zero. Please note that i have not set the maximum width of the TextView.I want to get it runtime.


android - textview multiline problem

I am having two textviews in my linear layout i am facing the below visibility there Hi asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf here "Hi" is one textview and "asdf..." is one textview. But i want the visibility like below Hi asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf ...


Android: TextView - Multiline EditText with Disabled Soft Keypad?

In an app that I am writing I use the "singleLine" property of an EditText (inherited from TextView) in order to make the view multiline by setting the property to false: mCalculatorInput.setInputType(InputType.TYPE_NULL); mCalculatorInput.setSingleLine(false); The reason for this is the line above it, where I disable all use of the soft keypad in order to use my own keypad (calculator). ...


android - How to make textView wrap its multiline content exactly?

How can I make the textview wrap such text exactly ? android:width attribute is not a solution, because the text is dynamic. Desired behaviour |Adcs | |adscfd| Current behavour: |Adcs | |adscfd | Hereis the code (styles of TextViews only define things like textColor, textSize, textStyle). <TextView ...


android - Multiline TextView without words wrapping on 4.x?

I want to create a TextView that does NOT wrap text, and allow vertical/horizontal scrolling? The solution described here no longer works on 4.0.3. Is there any solution for 4.x?


android - Textview autofit with multiline support

i've looked for solutions of auto-fitting the font of the textView according to its size , and found many , but none support multi-lines and does it correctly (without truncating the text and also respect the gravity values) . has anyone else conducted a solution as such? is it also possible to set the constraint of how to find the optimal number of lines ? maybe according to max font size or max character...


eclipse - Android: placing button below multiline textview

I am designing an Android application and I'm stuck. Tried a lot of thing but nothing helped so far. I have an activity with multiple TextViews and buttons. One of those textviews holds an address, but it can be multiline. So sometimes it has 1 line, other times up to maximum 4. Now i want to place a button underneath. When the textview only has 1 line, no problem, but when it has more, the text goes over my button. Here i...


android - How to fit multiline text inside a TextView using a custom font?

I'm using API 10. I am stuck with this for days. I searched stackoverflow and tried a ton of classes. I wanted to fit a multiline text inside my TextView bounds with the default font. I used the class below and it worked wonders, and not only one one device, but on all devices. Exactly the same. The code is this, I found it in stackoverflow:


android - TextView multiline clipping in TableRow

I have searched for couple of hours about this problem, but found no helping solution. Here is the problem The textview at [0, 0] got clipped when using multiline. And here is xml code. <TextView android:id="@+id/testtextView" android:layout_width="wrap_content" a...


view - android: tablerow mixed with columns and multiline text

I am trying to have a tablelayout contains several tablerows. One of the rows contains 4 buttons, while the second row contains a very long text. However, the width of the button stretches with the text in the second row. Is there anyway to prevent this?


android - Custom fonts, ellipsis on MultiLine TextViews, Glyphs and glitches

I am required to use custom fonts in my application. Problem: For ListViews that contain rows with Multi-Line TextViews having ellipsize property set to true, I can see some illegible characters after the ellipsis. Apparently Android pads the String(in TextView) with some characters(ZERO WIDTH NO BREAK-SPACE) unknown to my custom font. Single line TextView seem to work just fine...


retrieve EditText multiline text as it is android?

I want to get text from Edit text as it is and display in TextView.But whenver i get text using getText() it gives me text in one line. How to entered text in multiline EditText as it is. Please give me guidance?


android - Clearing a multiline EditText

I am trying to clear a multiline EditText field inside the OnEditorActionListener.onEditorAction method. But using any of the obvious ways i.e. ((EditText) view).getEditableText().clear(); ((EditText) view).getEditableText().clearSpans(); ((EditText) view).setText(""); only clears the visible characters - leaving the the newlines in the field (which then have to be manually delet...


android - Multiline EditText with Done SoftInput Action Label on 2.3

Is there a way to have a Multi-Line EditText present and use the IME Action Label "Done" on Android 2.3? In Android 2.2 this is not a problem, the enter button shows the IME Action Label "Done" (android:imeActionLabel="actionDone"), and dismisses Soft Input when clicked. When configuring an EditText for multi-line, Android 2.3 removes the ability to show the "Done" ac...


multiline textview in android

in this activity, i have two textview in first textview, the last line has only two character so it looks like some odd. so i want to check the last line of textview, and if the number of character in last line is less than 10 then i want to remove that character from line 1. so how can i get the last line characters? help me


android - multiline ellipsis in textView - is this a known bug?

I want to display only 6 lines in my TextView and anything more i would like to ellipsise that. So, i did <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:paddingLeft="20dip" android:paddingRight="40dip" android:textSize="18dip" android:paddi...


multiline text alignment of EditText in android

I want to write an android application which can perform text alignment task like microsoft word.Whole text alignment is possible but not for every line.I want to set different alignment for different line.How can I do this.


layout - How to get maximum width of multiline TextView in android?

I am new in android and facing the problem to get the maximum width of the multiline TextView. I used textview.getWidth() and textview.getMeasuredWidth() but both gives garbage value. I used also textview.length(), but retuns zero. Please note that i have not set the maximum width of the TextView.I want to get it runtime.


android - textview multiline problem

I am having two textviews in my linear layout i am facing the below visibility there Hi asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf here "Hi" is one textview and "asdf..." is one textview. But i want the visibility like below Hi asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf ...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top