//自定义toast private void customToast(){ //得到inflater对象和view LayoutInflater inflater=getLayoutInflater(); View layout=inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root)); //得到view下的相应的控件 ImageView image = (ImageView) layout.findViewById(R.id.image); image.setImageResource(R.drawable.ic_launcher); TextView text = (TextView) layout.findViewById(R.id.text); text.setText("Hello! This is a custom toast!"); //设置toast Toast toast=new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout); toast.show(); }
Android之Notification实现
内容版权声明:除非注明,否则皆为本站原创文章。