/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;
} }

demo16Toast的更多相关文章

随机推荐

  1. SHELL 八大扩展

    最近在梳理bash知识的的过程中,有幸阅读了man bash文档,一时间犹如醍醐灌顶一般,很多当初不明白的地方都豁然开朗,现在就其中的一点做一分享,同时也为man bash做一下广告,当你面对bash ...

  2. mysql binlog恢复

    MySQL Binary Log也就是常说的bin-log, ,是mysql执行改动产生的二进制日志文件,其主要作用有两个: * 数据回复 * 主从数据库.用于slave端执行增删改,保持与maste ...

  3. J2SE 1.6 特性:java.lang.instrument

    1. import java.lang.instrument.Instrumentation; public class ObjectSizeFetcher { private static Inst ...

  4. mvc EF 数据保存时,报错:”对一个或多个实体的验证失败……“之解决

    在EF5.0添加实体数据到数据库的时候,出现“对一个或多个实体的验证失败.有关详细信息,请参见“EntityValidationErrors”属性这个错误 解决: SaveChanges前先关闭验证实 ...

  5. MongoDB过过瘾

    MongoDB 中默认的数据库为 test,连接后尝试以下操作 连接 插入数据:用过json的同学看到这格式相信不会陌生吧! db.person.insert({}) db.person.insert ...

  6. ligerui ligerTip气泡提示信息

    onAfterShowData:function(){ $('.l-grid-row-cell-inner').hover(function (){ $(this).ligerTip({content ...

  7. QQ聊天气泡(图片拉伸不变样)、内容尺寸定制(高度随字数、字体而变)

    - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; /** QQ聊 ...

  8. Using Feedback as a Tool

    As a project manager it is important to be able to give and receive feedback effectively. Feedback i ...

  9. [RVM is not a function] Interating RVM with gnome-terminal

    Ubuntu 12.04 64bit LTS, running the 'rvm use 1.9.3' brings the 'RVM is not a function' warning. Here ...

  10. 针对应用程序池“xxxxxx”的模板永久性缓存初始化失败,解决方法

    日志名称:          Application 来源:            Active Server Pages 日期:            2014-11-22 9:09:39 事件 I ...