如何将粗体文本设置为Android Snackbar操作文本? [英] How to set Bold text to Android Snackbar Action Text?

查看:117
本文介绍了如何将粗体文本设置为Android Snackbar操作文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

setActionTextColor为Snackbar的操作文本设置颜色. rel ="noreferrer"> https://developer.android.com/reference/android/support/design/widget/Snackbar.html .但是,有没有办法使文本变为粗体?

We could set the color for the Action Text of Snackbar using setActionTextColor as documented in https://developer.android.com/reference/android/support/design/widget/Snackbar.html. However, is there a way to make the Text BOLD?

谢谢!

推荐答案

使用snackbar_action资源ID.

轮到您,您可以使用与设置Snackbar的操作"文本样式相同的方法来设置Snackbar的操作"文本.

Use snackbar_action Resource ID.

It turns you that you can use the same method to style the Snackbar's Action text that you use to style the Snackbar's Message text.

您只需要使用资源ID snackbar_action而不是snackbar_text.

You just have to use the Resource ID snackbar_action instead of snackbar_text.

下面是为消息文本和操作文本设置样式的示例.

Here's an example of setting the style for both the Message text and the Action text.

Snackbar snackbar = Snackbar.make( ... )    // Create the Snackbar however you like.

TextView snackbarActionTextView = (TextView) snackbar.getView().findViewById( android.support.design.R.id.snackbar_action );
snackbarActionTextView.setTextSize( 20 );
snackbarActionTextView.setTypeface(snackbarActionTextView.getTypeface(), Typeface.BOLD);

TextView snackbarTextView = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
snackbarTextView.setTextSize( 16 );
snackbarTextView.setMaxLines( 3 );

在我的示例中,我将操作"文本的TextSize设置为20,加粗的Typeface,将消息"文本的TextSize设置为16,最多允许3行.

In my example, I've set the Action text to have a TextSize of 20 and a bold Typeface, and the Message text to have a TextSize of 16 and allow up to 3 lines.

这篇关于如何将粗体文本设置为Android Snackbar操作文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆