java斜体_设置TextView样式(粗体或斜体)
回答(21)
2 years ago
TextView text = (TextView)findViewById(R.layout.textName);
text.setTypeface(null,Typeface.BOLD);
2 years ago
Hello, %1$s! You have <b>%2$d new messages</b>.
并调用formatHtml(string)
Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
CharSequence styledText = Html.fromHtml(text);
2 years ago
试试这个:
TextView textview = (TextView)findViewById(R.id.textview_idname);
textview.setTypeface(null,Typeface.BOLD);
2 years ago
由于我想使用自定义字体,因此只有几个答案的结合对我有用 . 显然我的 layout.xml 中的设置如_366798_被AOS忽略了 . 所以最后我必须做如下:在 strings.xml 中,目标字符串被声明为:
The information blah blah ...
然后另外在代码中:
TextView textSign = (TextView) findViewById(R.id.txt_sign);
FontHelper.setSomeCustomFont(textSign);
textSign.setTypeface(textSign.getTypeface(), Typeface.ITALIC);
我没有尝试 Spannable 选项(我认为必须工作)但是
textSign.setText(Html.fromHtml(getString(R.string.txt_sign)))
没有效果 . 此外,如果我从 strings.xml 删除 italic tag ,只留下 setTypeface() 它也没有效果 . 棘手的Android ......
2 years ago
你可以尝试这样:
Your Text
2 years ago
尝试将此设置为 TextView 为粗体或斜体
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
textView.setTypeface(textView.getTypeface(), Typeface.ITALIC);
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC);
2 years ago
你可以做的一种方法是:
myTextView.setTypeface(null, Typeface.ITALIC);
myTextView.setTypeface(null, Typeface.BOLD_ITALIC);
myTextView.setTypeface(null, Typeface.BOLD);
myTextView.setTypeface(null, Typeface.NORMAL);
另一种选择,如果你想保留以前的字体而不想丢失先前应用的那么:
myTextView.setTypeface(textView.getTypeface(), Typeface.NORMAL);
myTextView.setTypeface(textView.getTypeface(), Typeface.BOLD);
myTextView.setTypeface(textView.getTypeface(), Typeface.ITALIC);
myTextView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC);
2 years ago
这将是
yourTextView.setTypeface(null,Typeface.DEFAULT_BOLD);
和italic应该能够用 Typeface.DEFAULT_ITALC 替换 Typeface.DEFAULT_BOLD .
让我知道它是如何工作的 .
2 years ago
最好的方法是在 styles.xml 中定义它
@dimen/common_txtsize_heading
@color/color_black
bold|italic
并在 TextView 更新它
android:id="@+id/txt_userprofile"
style="@style/common_txt_style_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/margin_small"
android:text="@string/some_heading" />
2 years ago
尝试通过java代码设置 TextView 样式
txt1.setTypeface(null,Typeface.BOLD_ITALIC);
2 years ago
你有两个选择:
Option 1 (仅适用于粗体,斜体和下划线):
String s = "Bolded text, italic text, even underlined!"
TextView tv = (TextView)findViewById(R.id.THE_TEXTVIEW_ID);
tv.setText(Html.fromHtml(s));
Option 2:
使用Spannable;它更复杂,但您可以动态修改文本属性(不仅是粗体/斜体,还有颜色) .
2 years ago
以编程方式:
您可以使用 setTypeface() 方法以编程方式执行:
下面是默认字体的代码
textView.setTypeface(null, Typeface.NORMAL); // for Normal Text
textView.setTypeface(null, Typeface.BOLD); // for Bold only
textView.setTypeface(null, Typeface.ITALIC); // for Italic
textView.setTypeface(null, Typeface.BOLD_ITALIC); // for Bold and Italic
如果你想设置自定义字体:
textView.setTypeface(textView.getTypeface(), Typeface.NORMAL); // for Normal Text
textView.setTypeface(textView.getTypeface(), Typeface.BOLD); // for Bold only
textView.setTypeface(textView.getTypeface(), Typeface.ITALIC); // for Italic
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC); // for Bold and Italic
XML:
您可以直接在 中的XML文件中设置,如下所示:
android:textStyle="normal"
android:textStyle="normal|bold"
android:textStyle="normal|italic"
android:textStyle="bold"
android:textStyle="bold|italic"
或者您可以设置您的fav字体(来自资产) . 了解更多信息see link
2 years ago
这是配置OnePlus Slate™字体的OnePlus 5T上唯一有用的东西:
textView.setTypeface(Typeface.create(textView.getTypeface(), useBold ? Typeface.BOLD : Typeface.NORMAL));
其他方法会使其在BOLD或NORMAL时回退到Roboto .
2 years ago
AppCompatTextView text =(AppCompatTextView)findViewById(R.layout.appCompatTextView1);
text.setTypeface(null,Typeface.BOLD);
使用上述方法以编程方式设置字体 .
2 years ago
textView.setTypeface(null, Typeface.BOLD_ITALIC);
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);
textView.setTypeface(null, Typeface.NORMAL);
保留以前的字体
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC)
2 years ago
以编程方式:
您可以使用 setTypeface() 以编程方式执行:
textView.setTypeface(null, Typeface.NORMAL); // for Normal Text
textView.setTypeface(null, Typeface.BOLD); // for Bold only
textView.setTypeface(null, Typeface.ITALIC); // for Italic
textView.setTypeface(null, Typeface.BOLD_ITALIC); // for Bold and Italic
XML:
您可以在 中直接在XML文件中设置:
android:textStyle="normal"
android:textStyle="normal|bold"
android:textStyle="normal|italic"
android:textStyle="bold"
android:textStyle="bold|italic"
2 years ago
执行此操作的标准方法是使用自定义样式 . EX-
在 styles.xml 中添加以下内容 .
bold|italic
将此样式应用于 TextView ,如下所示 .
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/MyApp.TextAppearance.LoginText" />
2 years ago
只是如果你想制作文字 bold . 在文本视图属性的布局中写下此行
android:textStyle="bold"
2 years ago
TextView text = (TextView)findViewById(R.id.THE_TEXTVIEW_ID);
现在设置 textview 属性..
text.setTypeface(null, Typeface.BOLD); //-- for only bold the text
text.setTypeface(null, Typeface.BOLD_ITALIC); //-- for bold & italic the text
text.setTypeface(null, Typeface.ITALIC); // -- for italic the text
2 years ago
使用 textView.setTypeface(Typeface tf, int style); 设置TextView的样式属性 . 有关详细信息,请参阅developer documentation .
2 years ago
就我而言:
1 - 设置文字
2 - 设置字体
holder.title.setText(item.nome);
holder.title.setTypeface(null, Typeface.BOLD);
java斜体_设置TextView样式(粗体或斜体)相关推荐
- python font 斜体_用PIL绘制粗体/斜体文字?
嗯,这是我的第一个评论.我们走了. 我会尝试澄清这个程序.起初我做的是使用" name"像这样的字体 font = ImageFont.truetype("C:\Wind ...
- Android也行5view斜体,Android TextView同时设置粗体和斜体
Android TextView同时设置粗体和斜体 效果图 问题 TextView的粗体和斜体无法同时生效,要么显示斜体,要么显示粗体. 错误代码: tv_test3.setTypeface(Type ...
- Android TextView同时设置粗体和斜体
Android TextView同时设置粗体和斜体 效果图 问题 TextView的粗体和斜体无法同时生效,要么显示斜体,要么显示粗体. 错误代码: tv_test3.setTypeface(Type ...
- android 字体加下划线,如何在Android TextView中将字体样式设置为粗体,斜体和下划线?...
我想让TextView的内容变得粗体,斜体和下划线. 我尝试了如下代码而且它能够工做,但没有强调. android 我该怎么作? 任何快速的想法? 编程 #1楼 这是添加下划线的简单方法,同时保持其余 ...
- java斜体_设置标签字体用粗体和斜体
我正在尝试将我的标签的特定部分设置为粗体和斜体 NSMutableAttributedString ,但我只能得到一个或另一个 . 故事板上的'm using is Clear Sans. Setti ...
- 如何设置TextView textStyle,例如粗体,斜体
如何在Java中设置TextView样式(粗体或斜体)而不使用XML布局? 换句话说,我需要用Java编写android:textStyle . #1楼 TextView text = (TextVi ...
- Python3-word文档操作(十):利用docx库创建word文档,添加段落,添加表格,添加图片,设置文字粗体,斜体
1 简介: 作为一个综合例子,本篇主要显示docx库的一些基本操作: 利用docx库创建word文档,添加段落,添加表格,添加图片,设置文字粗体,斜体. 2 举例: 对word文档进行属性的设置,以及 ...
- 设置字体同时为粗体、斜体
设置字体样式操作比较简单,如下语句: FontStyle style = FontStyle.Bold; 即可设置字体样式为粗体.当需要设置字体样式同时具有多种风格时,可以采用按位或 ...
- R语言ggplot2可视化:通过在element_text函数中设置ifelse判断条件自定义标签文本的显示格式:例如、粗体、斜体等
R语言ggplot2可视化:通过在element_text函数中设置ifelse判断条件自定义标签文本的显示格式:例如.粗体.斜体等 目录
最新文章
- BZOJ 1799 [Ahoi2009] self 同类分布(数位DP)【BZOJ千题计划(quexin】
- CentOS7 部署 galera cluster mariadb 10.1
- centos7挂载windows共享文件夹
- There is insufficient system memory to run this query 错误
- java 怎么链接ndk的库_使用ndk-build链接现有的静态库
- win7计算机双击空白,win7系统控制面板“打开或关闭Windows 功能”空白没有任何选项的解决方法...
- Uva 524 相邻素数全排列
- 操作系统高响应比优先调度算法代码_进程调度
- mysql数据库笔记 约束_MySQL数据库笔记四:MySQL的约束
- 经典面试题之赋值操作
- iOS之healthKit
- 一个INT 10H中断的小例子
- matlab2014如何获得hostid,关于如何修改hostid的问题
- 怎样解除网络宽带限制
- neu1482 2014辽宁省赛Picking Cabbage(状态压缩)
- 类型的Overflow与underflow
- thinkphp 重构
- 什么是background-attachment
- git squash
- 第一个算出地球周长的人
热门文章
- JCA Overview
- 读不完《程序员修炼之道》,至少可以读完这70条
- 【Java 代码实例 14】BeanUtils用法详解,附源码分析
- 37岁的老大叔零基础学python,来点鼓励吧
- 在Python中文件用Feather格式,与 CSV说再见,速度提升 150 倍!
- caj格式转换成pdf免费的有吗
- 想不到 HR 都在 GitHub 捞人!五位开源大牛分享成长经历(文末福利)
- 已解决-Mounty 挂载NTFS报错:卷“BOOTCAMP“不可重新挂载
- 【JavaWeb - 网页编程】三 jQuery 类库
- 服务质量(QoS)--网络大典