安卓开发如何自定义字体

   下面有段代码关于android 自定义字体 希望对安卓软件的开发人员有一定的帮助!
 
    android:自定义字体;
    static public void setFont(Context context, ViewGroup containerLayout) {
    Typeface typeface = Typeface.createFromAsset(context.getAssets(),
            "fonts/Comfortaa-Regular.ttf");

    View view;
    ViewGroup viewGroup;
    TextView textView;
    Button button;
    int count = containerLayout.getChildCount();
    for (int i = 0; i < count; i++) {
        view = containerLayout.getChildAt(i);

        if (view instanceof ViewGroup) {
            viewGroup = (ViewGroup) view;
            setFont(context, viewGroup);
        } else if (view instanceof TextView) {
            textView = (TextView) view;
            textView.setTypeface(typeface);
        }
    }
}

// 调用上面的代码。
ViewGroup containerLayout = (ViewGroup) findViewById(R.id.containerLayout);
TypeFaceHelpers.setFont(this.getApplicationContext(), containerLayout);

转载于:https://www.cnblogs.com/zxdong/archive/2012/04/25/2470135.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值