且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将粗体文本设置为Android Snackbar操作文本?

更新时间:2023-01-27 21:19:44

使用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.