开发者

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

开发者 https://www.devze.com 2023-04-08 15:44 出处:网络
This question already has answers here: Closed 11 years ago. 开发者_开发技巧 Possible Duplicate:
This question already has answers here: Closed 11 years ago.
开发者_开发技巧

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号