我想设置样式或字体在TextView
像图像文字如下图所示:如何设置样式或字体为TextView的文本在android中?
4
A
回答
11
您需要自定义字体,然后才能执行此操作:
Typeface mFont = Typeface.createFromAsset(getAssets(), "fonts/myFont.ttf");
MyTextView.setTypeface(mFont);
您必须在资产文件夹中创建“字体”文件夹。把你的字体放在那里。
您当然也可以创建自定义TextView
。如果你喜欢,请参考this answer,我给了一段时间。
7
<TextView
style="@style/CodeFont"
android:text="@string/hello" />
你需要做的是codefont风格:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
直接从:http://developer.android.com/guide/topics/ui/themes.html
0
您可以创建一个layout.xml文件,其中包含您的textview。例如:
textView.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
style="@android:style/Holo.ButtonBar" >
如果你不想要这个,那么你可以创建自定义样式。事情是这样的:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Custom" parent="@android:style/TextAppearance.Large" >
<item name="android:typeface">monospace</item>
</style>
</resources>
,并在布局文件中改变风格的东西,如:
style="@style/Custom"
3
还有另一种方式,如果你想改变它在许多TextViews,使用类:
public class MyTextView extends TextView {
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyTextView(Context context) {
super(context);
init();
}
private void init() {
if (!isInEditMode()) {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/Ubuntu-L.ttf");
setTypeface(tf);
}
}
}
,并在布局取代:
<TextView
...
/>
有了:
<com.WHERE_YOUR_CLASS_IS.MyTextView
...
/>
相关问题
- 1. 如何在android中为TextView设置字体?
- 2. 如何在android中设置字体为textview?
- 3. 如何在android中为textview设置telugu字体?
- 4. 如何在Android TextView中将字体样式设置为粗体,斜体和下划线?
- 5. 如何在textview中设置telugu字体?
- 6. 如何设置字体样式在FPDF
- 7. 如何在Android中为特定文本视图设置字体?
- 8. 如何在Android中设置textView的字体?
- 9. 如何将蹦极字体样式给android中的textview?
- 10. 如何在Android textview中设置字体宽度?
- 11. 文本中的样式(textView)
- 12. 设置包含文本的自定义视图的样式或字体,如默认的TextView?
- 13. 如何在字段中设置占位符文本的样式?
- 14. 在ListActivity中为TextView设置文本
- 15. 如何将android字符串保存为文本文件,然后设置为textview?
- 16. toolStripComboBox设置字体样式?
- 17. 如何在Safari和Chrome中设置文本字段样式
- 18. 使用Java在Webdriver中设置文本样式(颜色,粗体或斜体)
- 19. 更改textView中的字体样式?
- 20. 如何在Android Studio API 10中设置TextView文本颜色
- 21. 如何在iOS中更改textview的字体系列和样式?
- 22. 如何在android textview中使用文本对齐方式并同时使用自定义字体样式?
- 23. 如何将静态标签中的文本设置为粗体样式?
- 24. 如何在html中设置文本脚本的样式?
- 25. 将文本设置为textview在Android代码中返回null
- 26. 如何在Android中设置自定义不同的字体样式
- 27. 不同的提示字体样式和键入的文本字体样式android
- 28. 如何在黑莓中将字体设置为LabelField文本?
- 29. 如何在TextView中指定字体样式
- 30. 设置TextView的文本样式TextAppearance.Appcompat ...编程
由于其完全为我工作。 – 2013-02-27 13:49:14