Toast
2015-08-30 22:38
281 查看
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="提交"/> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="自定义toast"/> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textview_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我是标题"/> <ImageView android:id="@+id/imageview_toast" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <TextView android:id="@+id/textview_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我是内容"/> </LinearLayout>
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private Button mButton1; private Button mButton2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mButton1= (Button) findViewById(R.id.button1); mButton2= (Button) findViewById(R.id.button2); mButton1.setOnClickListener(this); mButton2.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.button1: Toast toast= Toast.makeText(getApplicationContext(), "我是Toast", Toast.LENGTH_LONG); Spanned spanned= Html.fromHtml("我<img src=''/>是<img src=''/>一个<font color='#ff0000'>toas</font>", new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { Drawable drawable =getResources().getDrawable(R.mipmap.ic_launcher); drawable.setBounds(0,0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight()); return drawable; } },null); toast.setText(spanned); toast.setDuration(Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER|Gravity.BOTTOM,0,0); toast.show(); break; case R.id.button2: Toast toast1=Toast.makeText(getApplicationContext(),"我是Toast", Toast.LENGTH_LONG); LayoutInflater inflater=getLayoutInflater(); View view=inflater.inflate(R.layout.activity_toast,null); toast1.setView(view); toast1.setDuration(Toast.LENGTH_LONG); toast1.show(); break; default: break; } }
相关文章推荐
- stringstream
- Android Studio 初相遇
- Unity3D官方案例--SurvivalShooter游戏总结
- Redis集群:redis主从自动切换Sentinel
- 使用线程的几种方式(1) 流水线
- crontab命令
- uoj #31. 【UR #2】猪猪侠再战括号序列 贪心
- Javascript
- JSON(一):基本语法
- 探索Java反射机制
- 基于天天动听API开发在线音乐查询网站
- 1031. 查验身份证(15)
- scrollview 嵌套listview刷新问题
- Java依赖注入库框架 Dagger的源码分析(一)
- trait里的默认函数会为每个类型拷贝一份
- 网络协议之访问服务端的三种方式
- hihocoder #1223 : 不等式
- 设计模式14:Command 命令模式(行为型模式)
- html5学习之路_005
- 如何在linux下判断web服务是否开启?