How can I change default toast message color and background color in android?

后端 未结 15 870
执念已碎
执念已碎 2020-12-23 17:12

I want to create a toast message with background color is white and message color is black. My toast message is:

Toast.makeText(Logpage.this, \"Please Give          


        
15条回答
  •  感动是毒
    2020-12-23 17:53

    static void CustomToast(Context context, String text, int duration,
                                        @Nullable Integer backgroundColor,
                                        @Nullable Integer textColor){
            Toast t = Toast.makeText(context,text,duration);
            if (backgroundColor != null)
                t.getView()
                        .setBackgroundTintList(ColorStateList.valueOf(backgroundColor));
            if (textColor != null)
                ((TextView)t.getView().findViewById(android.R.id.message))
                        .setTextColor(textColor);
            t.show();
        }
    

提交回复
热议问题