TextView部分文字设置指定颜色和大小和字体

转载:http://blog.csdn.net/qq435757399/article/details/42921357#

1.在string.xml文件中:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <string name="exchange_txt_hint"><Data><![CDATA[请使用<font color="#ff0000"><b>%1$s</b></font>牛兑换<font color="#00ff00"><b>%2$s</b></font>%3$s 上网时长]]></Data></string>  

2. 在Java代码中

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. tv = (TextView) findViewById(R.id.tv);  
  2.         String exchange = getResources().getString(R.string.exchange_txt_hint);  
  3.   
  4.                 tv.setText(Html.fromHtml(exchange));  

效果图:



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Android TabLayout中设置字体,你可以使用自定义的TabLayout.TabView来实现。以下是一种可能的实现方法: 1. 创建一个自定义的TabView布局文件,例如"custom_tab_layout.xml": ```xml <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="@color/tab_text_color" android:textSize="@dimen/tab_text_size" android:fontFamily="@font/custom_font" /> ``` 在上面的布局中,你可以通过设置"android:fontFamily"属性来指定自定义字体。 2. 在你的Activity或Fragment中,获取TabLayout的Tab对象并设置自定义的TabView布局: ```java TabLayout tabLayout = findViewById(R.id.tab_layout); for (int i = 0; i < tabLayout.getTabCount(); i++) { TabLayout.Tab tab = tabLayout.getTabAt(i); if (tab != null) { tab.setCustomView(R.layout.custom_tab_layout); TextView tabTextView = tab.getCustomView().findViewById(android.R.id.text1); tabTextView.setText(tab.getText()); } } ``` 在上述代码中,我们为每个Tab设置了自定义的TabView布局,并通过findViewById获取到自定义布局中的TextView设置文本。 请确保将"R.layout.custom_tab_layout"替换为你自己的自定义TabView布局文件。 同时,你也可以根据需要在自定义TabView布局文件中设置其他样式,如文本颜色大小等。 这样,你就可以在Android TabLayout中设置自定义字体了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值