开发者

How to make a TextView bold?

开发者 https://www.devze.com 2023-01-18 07:53 出处:网络
I want to be able to make a TextView bold. This is how I am setting it\'s appearance (I need to do this in code):

I want to be able to make a TextView bold. This is how I am setting it's appearance (I need to do this in code):

nameText.setTextAppearance(getApplicationContext(), R.style.BlueText);
priceText.setTextAppearance(getApplicationContext(), R.style.BlueT开发者_运维百科ext);
changeText.setTextAppearance(getApplicationContext(), R.style.BlueText);

Here is my style.xml

  <!-- Blue Color -->
   <style name="BlueText">
        <item name="android:textColor">#4871A8</item>
    </style>

How can I make sure my TextView is bolded?


  <!-- Blue Color -->
   <style name="BlueText">
        <item name="android:textColor">#4871A8</item>
        <item name="android:textStyle">bold</item>
    </style>


On a related note, if you want to do the same without any XML at all, you can do this:

TextView myText = new TextView(this);
myText.setTextColor(Color.BLUE);
myText.setTypeface(Typeface.DEFAULT_BOLD);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号