- 浏览: 248312 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (289)
- java (72)
- oracle (3)
- mysql (5)
- spring (28)
- hibernate (2)
- osgi (0)
- linux (2)
- ExtJs (1)
- jvm (0)
- mybatis (7)
- 分布式 (11)
- MINA (6)
- apache+tomcat (13)
- js+htm (7)
- android (44)
- http (1)
- hbase+hdoop (0)
- memcache (13)
- search (27)
- 部署及性能 (12)
- mongoDB (2)
- 多线程 (12)
- 安全管理验证 (9)
- struts (1)
- webservice (0)
- easyUI (1)
- spring security (16)
- pattern (6)
- 算法 (2)
最新评论
-
lzh8189146:
CommonsHttpSolrServer这个类,现在是不是没 ...
CommonsHttpSolrServer -
xiaochanzi:
我按照你的方法试了下,tomcat6可以发布,但是访问任何网页 ...
基于内嵌Tomcat的应用开发 -
phoneeye:
麻烦你,如果是抄来的文章,请给出来源。谢谢
ant 两则技巧 -
neverforget:
转载不注明出处
Spring Security3.1登陆验证 替换 usernamepasswordfilter -
liang1022:
若不使用eclipse ,如何在命令行下 运行服务端程序 ?
WebService CXF学习(入门篇2):HelloWorld
自定义Toast
- 博客分类:
- android
转载:若水
自定义Toast
分类: Android 2011-04-27 08:30 1849人阅读 评论(3) 收藏 举报
Android系统默认的Toast十分简洁,使用也非常的简单。但是有时我们的程序使用默认的Toast时会和程序的整体风格不搭配,这个时候我们就需要自定义Toast,使其与我们的程序更加融合。
使用自定义Toast,首先我们需要添加一个布局文件,该布局文件的结构和Activity使用的布局文件结构一致,在该布局文件中我们需设计我们Toast的布局,例如:
[xhtml] view plaincopy
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="#DAAA"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
</LinearLayout>
在这个地方要注意,我们给LinearLayout添加的id属性,在后面的代码中我们需要使用到。在程序中,我们可以通过如下代码创建我们自己的Toast。
[java] view plaincopy
/**
* @author coolszy
* @blog http://blog.csdn.net/coolszy
*/
public class MainActivity extends Activity
{
private Button btn;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//获取LayoutInflater对象,该对象能把XML文件转换为与之一直的View对象
LayoutInflater inflater = getLayoutInflater();
//根据指定的布局文件创建一个具有层级关系的View对象
//第二个参数为View对象的根节点,即LinearLayout的ID
View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root));
//查找ImageView控件
//注意是在layout中查找
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.head);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("自定义Toast演示程序");
Toast toast = new Toast(getApplicationContext());
//设置Toast的位置
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
//让Toast显示为我们自定义的样子
toast.setView(layout);
toast.show();
}
});
}
}
自定义Toast
分类: Android 2011-04-27 08:30 1849人阅读 评论(3) 收藏 举报
Android系统默认的Toast十分简洁,使用也非常的简单。但是有时我们的程序使用默认的Toast时会和程序的整体风格不搭配,这个时候我们就需要自定义Toast,使其与我们的程序更加融合。
使用自定义Toast,首先我们需要添加一个布局文件,该布局文件的结构和Activity使用的布局文件结构一致,在该布局文件中我们需设计我们Toast的布局,例如:
[xhtml] view plaincopy
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="#DAAA"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
</LinearLayout>
在这个地方要注意,我们给LinearLayout添加的id属性,在后面的代码中我们需要使用到。在程序中,我们可以通过如下代码创建我们自己的Toast。
[java] view plaincopy
/**
* @author coolszy
* @blog http://blog.csdn.net/coolszy
*/
public class MainActivity extends Activity
{
private Button btn;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//获取LayoutInflater对象,该对象能把XML文件转换为与之一直的View对象
LayoutInflater inflater = getLayoutInflater();
//根据指定的布局文件创建一个具有层级关系的View对象
//第二个参数为View对象的根节点,即LinearLayout的ID
View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root));
//查找ImageView控件
//注意是在layout中查找
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.head);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("自定义Toast演示程序");
Toast toast = new Toast(getApplicationContext());
//设置Toast的位置
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
//让Toast显示为我们自定义的样子
toast.setView(layout);
toast.show();
}
});
}
}
发表评论
-
android之ConnectivityManager简介,网络连接状态
2012-09-13 10:56 896转发:http://blog.csdn.net/chenzhe ... -
解决Android布局中ScrollView与ListView的冲突
2012-08-27 09:25 705http://06peng.com/read.php/7.ht ... -
APK_获取Android的APK包签名信息
2012-08-02 14:09 1243http://blog.csdn.net/jiguanghov ... -
Android系列之Android 命令行手动编译打包详解
2012-08-01 22:08 867http://blog168.chinaunix.net/sp ... -
Android屏幕锁定详解(一)
2012-06-17 21:35 776http://mzh3344258.blog.51cto.co ... -
android 获取手机通讯录信息
2012-06-15 17:28 1065android 获取手机通讯录信息 博客分类: androi ... -
Android Intent.ACTION_CHOOSER 与 Intent.ACTION_PICK_ACTIVITY
2012-06-15 14:02 1390http://blog.csdn.net/feng88724/ ... -
Android绘制进阶之一:图形的绘制
2012-06-15 11:28 707http://mikewang.blog.51cto.com/ ... -
Android画图之Matrix(一)
2012-06-14 16:53 674http://chroya.iteye.com/blog/71 ... -
Android Bitmap和Canvas学习笔记 Android Bitmap和Canvas学习笔记
2012-06-14 14:04 686http://www.pin5i.com/showtopic- ... -
Paint类介绍
2012-06-14 13:41 651** * Paint类介绍 * ... -
Android Activity和Intent机制学习笔记 打电话,发短信等练习
2012-06-12 13:22 1064http://ycl248.blog.163.com/blog ... -
taskAffinity属性
2012-06-12 13:22 648taskAffinity属性 分类: Android 2011 ... -
区分Activity的四种加载模式----以及Intent的setFlags
2012-06-12 13:22 664区分Activity的四种加载模式----以及Intent的s ... -
android 自带的主题 theme 的使用
2012-06-12 13:22 1102android 自带的主题 theme 的使用 2011 ... -
TextView小组件的使用--附带超链接和跑马灯效果
2012-06-07 08:40 768TextView小组件的使用--附带超链接和跑马灯效果 分类: ... -
EditText使用详解
2012-06-07 08:40 818EditText使用详解 分类: ... -
(转)解决requestFocus后依旧无法获得焦点问题
2012-06-07 08:40 1386(转)解决requestFocus后依旧无法获得焦点问题 博 ... -
android 在程序中开启GPS功能
2012-06-07 08:40 1032android 在程序中开启GPS功能 LocationMan ... -
转到手机设置界面
2012-06-06 16:34 0//转到手机设置界面 Intent intent=new In ...
相关推荐
自定义Toast,设置Toast显示位置,自定义Toast的复杂布局 博客地址:http://blog.csdn.net/xy_nyle/article/details/20137953
一个简单的自定义Toast资源,您可以根据自己的需要更改我的代码即可实现您想要的效果(主要是更改xml文件的布局),这是androidstudio的项目,但是不妨碍在eclipse中使用,可以直接在eclipse中新建android项目,然后将...
和对话框不同的是,Toast并不是以独占方式显示的,它并不会抢夺用户的焦点,在弹出Toast的时候,依然可以对之前的界面进行操作,我们在“”一文中介绍了纯文本的Toast的使用,我们完全可以自定义Toast的显示内容和...
主要为大家详细介绍了android自定义Toast设定显示时间,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
自定义Toast,类似Android的Toast
1.自定义Toast提示,高仿IOS的屏幕中间提示,效果可以参考android版腾讯新闻的提示。还有一个重要特点:多次连续点击不会产生多个Toast队列不停的一直显示,而是直接更新当前Toast的视图,效果绝对棒! 2.自定义加载...
Android中自定义Toast.pdf 学习资料 复习资料 教学资源
微信小程序自定义toast的源码,简单详细 具体步骤参考:http://blog.csdn.net/xxs18326183038/article/details/79281651
自定义toast 上下中带图片 加改造的日历选择控件
android 自定义toast,toast自定义显示时间,toast自定义显示样式
一个自定义Toast样式的demo,可以设置Toast的显示位置和显示内容
自定义Toast小部件是Flutter应用程序中非常实用的功能,它可以用于向用户提供各种通知和信息。在本文中,我们学习了如何创建一个简单的自定义Toast小部件,并讨论了如何添加一些进阶功能以满足不同的需求。希望这篇...
android Toast对象的使用 自定义Toast
自定义Toast,防止层叠显示问题,和自定义Toast样式 博客地址:https://blog.csdn.net/qq569699973
默认Toast(大家都会),自定义Toast位置,自定义Toast样式
包括普通Toast,自定义的图片Toast,自定义位置的Toast
自定义Toast及解决重复出现Toast的问题