LayoutInflater inflater = getLayoutInflater();//调用Activity的getLayoutInflater()
View view = inflater.inflate(R.layout.toast_style, null); //加載layout下的布局
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER, 12, 20);
//setGravity用来设置Toast显示的位置,相当于xml中的android:gravity或 //android:layout_gravity
toast.setDuration(Toast.LENGTH_LONG);
//setDuration方法:设置持续时间,以毫秒为单位。该方法是设置补间动画时间长度的主要方法
toast.setView(view); //添加布局
toast.show();
自定义toast样式
猜你喜欢
转载自blog.csdn.net/qq_34207101/article/details/85048194
今日推荐
周排行