/Users/alamps/AndroidStudioProjects/demo16Toast/demo16Toast/src/main/res/layout/activity_main.xml

<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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"> <Button android:id="@+id/_shortShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Short Toast" /> <Button android:id="@+id/_longShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Long Toast" /> <Button android:id="@+id/_customShow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="customShow Toast" /> </LinearLayout>
================
/Users/alamps/AndroidStudioProjects/demo16Toast/demo16Toast/src/main/java/com/example/demo16toast/MainActivity.java package com.example.demo16toast; import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast; public class MainActivity extends Activity {
private Button shortShow;
private Button longShow;
private Button customShow; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); this.shortShow = (Button)super.findViewById(R.id._shortShow);
this.longShow = (Button)super.findViewById(R.id._longShow);
this.customShow = (Button)super.findViewById(R.id._customShow); this.shortShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Short Toast show ",Toast.LENGTH_SHORT).show(); }
}); this.longShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Long Toast Show ",Toast.LENGTH_LONG).show();
}
}); this.customShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast customToast= Toast.makeText(MainActivity.this,"Custom Toast show ",Toast.LENGTH_LONG); customToast.setGravity(Gravity.CENTER,,); LinearLayout customToastView =(LinearLayout)customToast.getView();
ImageView customImageView= new ImageView(MainActivity.this);
customImageView.setImageResource(R.drawable.ic_launcher);
customToastView.addView(customImageView,);//在文字上方填加图片View
customToast.show();
}
}); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }

最新文章

  1. localStorage使用总结
  2. Greenlets间如何实现互相通信?
  3. TCP字节流和UDP数据报区别
  4. openssh for windows安装
  5. Android SDK中国在线更新镜像服务器 解决GOOGLE更新无法下载 更新失败的问题
  6. 【转】git在eclipse中的配置
  7. 【转】Linux下查看所有用户及用户组
  8. SQL Server中的DATEPART函数的使用
  9. Opencv 学习资料集合(更新中。。。)
  10. 自己定义android 4.0以上的对话框风格
  11. [bzoj4849][Neerc2016]Mole Tunnels
  12. ntoskrnl符号在IDA中查看的问题
  13. bash: jar: 未找到命令..(command not found)
  14. Express安装
  15. cookie特殊字符在游览器被转义
  16. creating server tcp listening socket 127.0.0.1:6379: bind No error
  17. Leet Code 3. Longest Substring Without Repeating Characters
  18. spring multipart源码分析:
  19. 将sublime添加到鼠标右键
  20. 何谓sdk,何谓api

热门文章

  1. Qt编写自定义控件大全(liudianwu)
  2. MongoDB过过瘾
  3. 其他常用HTML 片段
  4. 关于TCP传输速率的测量方法
  5. JS位操作符
  6. 分享一个移动项目中消除click事件点击延迟的方法
  7. PHP 数组和字符串互相转换实现方法
  8. 8月11日 Power-BI V11 QQ群视频交流开课啦
  9. 一个四叉树Demo学习
  10. ASP.NET在删除掉数据库文件后报错处理