I have 3 text views. I need to set their weight as Light, Regular and Condensed. Can someone help me on how to achieve this in Android?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Use
android:textStyle
on aTextView
to set the text style like bold, italic or normal.Here is an example of a
TextView
with a bold text style:If you want to use light or condensed, you will have to change your font. You can do it like this:
For more information about fonts, please also look at the following answer Valid values for android:fontFamily and what they map to?
You can only show a TextView as Light, Regular and Condensed if the font that you're referencing allows those styles.
For example, if you import a font into your project and it doesn't have Light or Condensed, I don't think it's (dare I say) possible to make the text appear with that style in your TextView. If you are importing your own font, work with it programmatically e.g. In your activity declare a global TextView:
Then in onCreate(), reference the fontfile you save in /assets:
Notice that I imported the condensed version of my font file (as .ttf), not as a packaged font .ttc. You can bring in various style versions of a font, but you should bring them in as individual .ttf files instead of one packaged file because you will want to reference the specific style .ttf.
However, if you're using a system font that allows you to reference various styles from your xml, see what they say here:
Valid values for android:fontFamily and what they map to?
As they say, for something like Roboto, you'll use the fontFamily.