安卓修改系统Toast 字体大小

 * Make a standard toast that just contains a text view.
 *

 * @param context  The context to use.  Usually your {@link android.app.Application}
 *                 or {@link android.app.Activity} object.
 * @param text     The text to show.  Can be formatted text.

 *                 {@link #LENGTH_LONG}
 *

 */

public static Toast makeText(Context context, CharSequence text, int duration) {
    Toast result = new Toast(context);

    LayoutInflater inflate = (LayoutInflater)
            context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
    TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
    tv.setText(text);

    result.mNextView = v;
    result.mDuration = duration;

    return result;
}

我们在Toast的源码里面可以看到在makeText方法里面 通过渲染R.layout.transient_notification这个布局来加载系统默认Toast,所以我们同样通过
getView方法获取布局再找到对应的TextView,就可以修改TextView的属性。下面是修改系统Toast的代码

Toast t = Toast.makeText(mActivity, R.string.setting_softupdate, Toast.LENGTH_LONG);
TextView tv = (TextView) t.getView().findViewById(com.android.internal.R.id.message);
 tv.setTextSize(23);
 t.show();
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值