在我的代码中,我有一个EditText,接受100到1000之间的值。我创建了一个自定义Toast,由gif和其他几个层组成,如下所示:
InputStream stream_loader_gif = null;
try
{
stream_loader_gif = getAssets().open("loader.gif");
}
catch (IOException e)
{
e.printStackTrace();
}
final GifDecoderView gif_view = new GifDecoderView( getBaseContext(), stream_loader_gif);
这是整个检查器:
if( (TextUtils.isEmpty( et_height.getText().toString())) || (Float.parseFloat(et_height.getText().toString())<100.0) || (Float.parseFloat(et_height.getText().toString())>1000.0) )
{
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate( R.layout.warning_toast_rebar, (ViewGroup) findViewById (R.id.warning_toast_rebar_xml) );
LinearLayout gifPresenter = (LinearLayout) layout.findViewById(R.id.gifView_at_toast_at_rebar);
gifPresenter.addView(gif_view);
TextView text = (TextView) layout.findViewById(R.id.text_at_toast_at_rebar);
text.setText("Height Must be Between 100 - 1000");
text.setTextSize(16);
text.setGravity(Gravity.CENTER);
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(30000);
toast.setView(layout);
toast.show();
//return;
}else{
height_val = Float.parseFloat(et_height.getText().toString());
}
运行代码后,它工作得很好,显示想要的Toast,然后我更正了值,系统说:“不幸的是,......”。