android自定义风格的toast
来源:互联网 发布:福岛核电站隐瞒知乎 编辑:程序博客网 时间:2024/05/22 04:59
先上图看一下我的自定义toast的样式
源码下载地址:
CustomToastActivity.java源码
package com.jinhoward.ui_customtoast;/** * Author :jinhoward * Date:2013-07-21 * Funtion: A toast of custom style. */import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.widget.Button;import android.widget.Toast;public class CustomToastActivity extends Activity {private Button button;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_custom_toast);button=(Button)findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubLayoutInflater inflater = getLayoutInflater();View customLayoutView = inflater.inflate(R.layout.toast_layout, null);Toast toast = new Toast(getApplicationContext());//设置toast为垂直居中显示toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);toast.setDuration(Toast.LENGTH_LONG);toast.setView(customLayoutView);toast.show();}});}}
activity_custom_toast.xml源码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#D1EEEE"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_gravity="center" android:text="显示自定义的Toast" /></LinearLayout>
toast_layout.xml源码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toast_layout_root" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#DAAAAA" android:orientation="horizontal" android:padding="8dp" > <ImageView android:id="@+id/ImageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/lock" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:paddingLeft="10sp" android:gravity="top|left|center" android:layout_toRightOf="@+id/ImageView1" android:textStyle="bold" android:text="这是一个自定义的toast!" android:textColor="#FF0000" /></RelativeLayout>
- android自定义风格的toast
- 自定义toast的风格。
- android 自定义Toast显示风格
- android 自定义Toast显示风格
- android 自定义Toast显示风格
- 关于Android 自定义Toast显示风格
- 自定义Toast 吐出我的风格
- Android:自定义的Toast
- 自定义Toast风格
- android 自定义Toast显示风格顶部弹出自定义时间
- Android自定义Toast取代系统的Toast
- android自定义的toast样式
- Android自定义Toast的使用
- Android自定义弹出的Toast
- Toast的不同风格
- Android 更改 Toast 的默认位置及自定义Toast
- android自定义风格的button
- [开源]在iOS上实现Android风格的控件Toast
- 带exists运算符的关联子查询(重点)
- Linux下几种RTP协议实现的比较和JRTPLIB编程讲解
- Xml+Xslt测试工具
- Linux中的硬链接和软链接
- JEECG 命名规范
- android自定义风格的toast
- 如何在Ubuntu中添加到PPA的软件源
- SQL之存储过程
- [smart210] 通过PLL设置各时钟频率的方法以及代码注释
- 外部中断练习
- HDU 2152
- 杭电2082-找单词
- 快速排序实现以及相关笔试题
- Hudson