How can we increase the font size in toast?

前端 未结 7 724
谎友^
谎友^ 2021-01-31 15:15

Is there any way to increase the font size in toast without customizing?

I don\'t want to create a layout for increasing the text size.

Is there any way?

7条回答
  •  暖寄归人
    2021-01-31 15:56

    Working from Ani's answer, another solution that allows you to set the text size to a dimension value would be something like:

    public static void showToast(Context context, int resId) {
        Toast toast = Toast.makeText(context, resId, Toast.LENGTH_LONG);
        LinearLayout toastLayout = (LinearLayout) toast.getView();
        TextView toastTV = (TextView) toastLayout.getChildAt(0);
        toastTV.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                context.getResources().getDimension(R.dimen.TEXT_SIZE));
        toast.show();
    }
    

    This lets you match the size you get your toasts to be the same size as specified in TextView and Button controls, for example.

提交回复
热议问题