demo16Toast
/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的更多相关文章
随机推荐
- 12 Most Useful Google Chrome Browser chrome:// Commands
1. chrome://flags 2. chrome://memory 3. chrome://about 4:chrome://net-internals 5:chrome://webrtc-in ...
- Difference between _, __ and __xx__ in Python
When learning Python many people don't really understand why so much underlines in the beginning of ...
- 在Windows 环境下编译Qt静态库(QT5.32)
参考链接 Qt5.3 Tools and Versions MinGW ICU ActivePerl Qt 安装MinGW工具链环境 这里在Win32环境下要安装一个MinGW工具链,这里最好是先安装 ...
- angularJS商品购物车案例
<!DOCTYPE html> <html ng-app="shopping"> <head lang="en"> < ...
- JavaScript正则表达式(三)
正则表达式可以: •测试字符串的某个模式.例如,可以对一个输入字符串进行测试,看在该字符串是否存在一个电话号码模式或一个信用卡号码模式.这称为数据有效性验证 •替换文本.可以在文档中使用一个正则表达式 ...
- table 操作
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- MFC之常用控件(四)
常用控件主要包括:静态文本框.编辑框.单选按钮.复选框.分组框.列表框.组合框.图片控件.列表控件.树形控件和进度条控件等等.本节教程先来讲解静态文本框的使用. 控件的通知消息 在将静态文本框的使用之 ...
- C++经典编程题#2:大象喝水
总时间限制: 1000ms 内存限制: 65536kB 描述 一只大象口渴了,要喝20升水才能解渴,但现在只有一个深h厘米,底面半径为r厘米的小圆桶(h和r都是整数).问大象至少要喝多少桶水才会解 ...
- LeetCode Course Schedule II
原题链接在这里:https://leetcode.com/problems/course-schedule-ii/ 题目: There are a total of n courses you hav ...
- android handler调用post方法阻塞
1.试下用postDelayed(Runnable a, int time),因为post把消息放到Looper中就返回,但Looper中没有其他消息又会被立刻取出来执行,这样就有可能做了run中的操 ...