Multiple fonts associated with same TextView - android

Is there any way to set different fonts for different states in a TextView?
Let's say I want Helvetica Regular for normal state, and Helvetica Bold for pressed?
I know how to link a custom font with a text view, but not sure how to do same for multiple fonts and single TextView? Specifically, is there a way to achieve this behaviour through xml?
Update: I'm not looking into workarounds, like having HTML in TextView, or even replacing TextView with WebView. If it's not possible to achieve, I'd rather have one font

check this link may help you:
http://shuklaxyz.blogspot.com/2012/05/custom-fonts-for-webview-and-textviewv.html
also :
Custom fonts and XML layouts (Android)
also:
Custom TrueType font from xml only
and this :
http://polwarthlimited.com/2013/05/android-typefaces-including-a-custom-font/
hope that help.

Using Html.fromHtml comes in handy, but it is limited to the tags you can use. I personally only have used this to do Bold, Colors, italics.
Like this:
String myWords ="<FONT COLOR = "#992211">This is Red:</FONT><br>";
myTextView.setText(Html.fromHtml(myWords));

Related

Android: using custom font as fallback font for missing glyph

is there anyway to set custom font as a fallback font to the default font?
I need to display some cjk characters not supported by android's default font (which I think is noto font for non latin characters). I have a custom font consists of the glyphs missing, so I'm thinking to use noto as the main font, and set my custom font as fallback.
The only way I can come up with is to make noto font as a typeface and set my custom font as fallback. Then I can assign this typeface to where I need it.
However, this mean I need to programmatically assign almost all textview in the app, which doesn't seem right... (and elegant😅)
I would like to ask what is the best practice for this scenario? Like, perhaps there's a way to declare them as a font family in XML?
Thanks a lot ;)
Let me answer myself :)
After trying, I think the easiest way is to merge two font files together.
Just make sure the font's license allows you to do so.

Syncfusion Xamarin.Forms formatted text in generated PDF

I want to ask you if it's possible to create formatted text like
This text is normal and this one is bold. We also have an italic font slope.
in this way:
graphics.DrawString("This text is normal and this one is bold. We also have an italic font slope.", font, PdfBrushes.Black, new PointF(0, 0));
I tried to use order the documentation a HTML Styled Text (https://help.syncfusion.com/file-formats/pdf/working-with-text#adding-a-html-styled-text) but PdfHTMLTextElement Class is not supported in Xamarin.
A next choice was to insert RTF text (https://help.syncfusion.com/file-formats/pdf/working-with-text#inserting-rich-text-format-contents) it's also impossible to use that in Xamarin.
I'd also to have a formatted string inside a cells of PdfLightTable. Have you any tips how to achieve this?
I'd appreciate your help very much.
At present the PdfHTMLTextElement is not supported in Xamarin platform. In order to achieve your requirement, we have created the workaround sample for applying style to the text based on HTML tags.
Please find the
Sample
Thanks.

set different fonts for hint and text in android

I am using floatlabelededittext in my application. My requirement is to set 2 different fonts for hint and text. Is it possible? Then how?
To have 2 different fonts for text and hint you need to use custom TypefaceSpan.
Set a font to a text by using usual setTypeface method
Set a font to a hint by using SpannableString
I already answered to that question Android EditText hint uses the same font that the EditText has
You can also keep the same font and change the hint's size and style independently. To know how, please, see my answer here
I don't think it is possible right now. But if you look at the source code of floatlabeledittext here https://github.com/wrapp/floatlabelededittext/blob/master/library/src/com/wrapp/floatlabelededittext/FloatLabeledEditText.java you see that it will be easy to add such feature.
All you need to do is to use setTypeface on the hint label mHintTextView.

Create a nice "About" XML Layout using rich text?

I intend to make a good "About" section in my application that gives the user some basic information about the developer and the app itself.
I didn't find a rich EditText among the Widgets.
I have searched for other questions similar to mine here and I found something like using a WebView or a TextView and giving them HTML attributes in the code.
Is there any nice and professional way to do my About XML Layout?
use multiple TextViews and position them accordingly.
If you need high control and rich text, use a WebView and load a static HTML file. You can achieve a lot with Spans (bold, itallick, links, etc.) in a simple TextView as well but it is generally more work.

can the layout of text in android views be controlled?

I am looking to format text line by line in a text view or similar. I want to be able to have line by line justifcation and formatting, almost like a word document (though nothing like as extensive)
I basically need to be able to have a continuous document with some parts right justified, some parts centered. Some bold, some not and some with a coloured background and some white. Also alowing the user to choose font.
Can someone recommend an decent approach to this please.
thanks
TextView/EditText operates on fairly rich text described by the various style span objects here: http://developer.android.com/reference/android/text/style/package-summary.html
For example you can use this to build text containing those various style spans: http://developer.android.com/reference/android/text/SpannableStringBuilder.html
SpannableStringBuilder is-a CharSequence, so it can be set as the text in a TextView. Though more often you probably just want to use TextView.getEditableText() to return the Editable interface to the text inside of the text view which allows you to modify its contents including style spans.
TextView supports most of what you are asking for through style spans, though justification is applied per-paragraph and not per-line. (Per-line is weird... I don't think even Word does such a thing?)
I would recommend using multiple TextViews. Possibly, one for each line if you really need the text that different. You can customize each one however you want fairly easily. If you haven't already, take a look at the documentation: http://developer.android.com/reference/android/widget/TextView.html
Then, you could use a RelativeLayout or a LinearLayout to position them however you need. Just ask if you have any other questions.

Categories

Resources