Android Toast带图标水平布局的简单实现
//创建Toast对象 |
02 |
Toast mToast = Toast.makeText(ShareYourLifeActivity. this , "内存卡不可用,请检查..." , Toast.LENGTH_LONG); |
03 |
|
04 |
//创建LinearLayout布局 |
05 |
LinearLayout toastView = (LinearLayout) mToast.getView(); |
06 |
|
07 |
//设置LinearLayout的布局取向 |
08 |
toastView.setOrientation(LinearLayout.HORIZONTAL); |
09 |
|
10 |
//创建ImageView |
11 |
ImageView imageCodeProject = new ImageView(getApplicationContext()); |
12 |
imageCodeProject.setImageResource(R.drawable.icon); |
13 |
|
14 |
//给toastView添加View布局 |
15 |
toastView.addView(imageCodeProject, 0 ); |
16 |
|
17 |
//显示Toast |
18 |
mToast.show(); |
19 |
|
20 |
图示:<IMG title=Toast带图标实例 alt=Toast带图标实例 align=left src= "http://static.oschina.net/uploads/space/2011/0722/174435_wYpq_122496.png" > |