How to Change the alignment of Toast by Programmatically? [duplicate]

爱⌒轻易说出口 提交于 2019-12-07 07:49:35

问题


Possible Duplicate:
how to change position of Toast in android?

How to change the Alignment for Toast? Basically, toast it'll displays information bottom of the device. How can we change that? Anyone help me to find out this? Thanks in Advance.


回答1:


It would be a nice idea to create a Custom Toast like this,

        TextView textview = new TextView(context);
        textview.setText(text);
        textview.setBackgroundColor(Color.GRAY);
        textview.setTextColor(Color.BLUE);
        textview.setPadding(10,10,10,10);
        Toast toast = new Toast(context);
        toast.setView(textview);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setGravity(Gravity.BOTTOM, 0, 0);
        toast.show();

By this you can place the Toast to anywhere you want using Gravity



来源:https://stackoverflow.com/questions/7537158/how-to-change-the-alignment-of-toast-by-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!