简体   繁体   English

如何在 java 中添加字体样式和粗体

[英]How to add font style and bold in java

Well, in the title is everything (I don't really know how to implement bold and font style in this specific code), code:好吧,在标题中就是一切(我真的不知道如何在这个特定的代码中实现粗体和字体样式),代码:

spinnerCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                ((TextView) parent.getChildAt(0)).setTextColor(Color.parseColor("#383163"));                                                                            
            }

        @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

You can use html code to add text and to represent bold text (using <b> ), convert this information into your TextView using Html.fromHtml()您可以使用 html 代码添加文本并表示粗体文本(使用<b> ),使用Html.fromHtml()将此信息转换为TextView

textView.setText(Html.fromHtml("Hello <b>world</b>, it is <b>vonAlt</b>"));

this is an example applied to your code:这是应用于您的代码的示例:

spinnerCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                ((TextView) parent.getChildAt(0)).setTextColor(Color.parseColor("#383163"));                                                                            
            }

        @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

Check this answer:检查这个答案:

TextView and Bold Text TextView 和粗体字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM