android中自定义toast样式
2016-01-25 00:00
519 查看
摘要: 修改toast的背景及出现位置
package cn.juzhong.view.widget; import cn.juzhong.R; import android.content.Context; import android.text.TextUtils; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; import android.widget.Toast; public class UiToast { Context mContext; String str; int id; public UiToast(Context context,String string){ mContext = context; str = string; } public UiToast(Context context,int id){ mContext = context; str = context.getResources().getString(id); } public void show(){ Toast toast = new Toast(mContext); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View contentView = inflater.inflate(R.layout.view_toast, null); TextView text = (TextView) contentView.findViewById(R.id.view_toast_textview); if(!TextUtils.isEmpty(str)){ text.setText(str); toast.setView(contentView); toast.setGravity(Gravity.TOP, Gravity.LEFT, Gravity.TOP + 100); toast.setDuration(Toast.LENGTH_SHORT); toast.show(); } } public String getStr() { return str; } public void setStr(String str) { this.str = str; } }
相关文章推荐
- scrollview与viewpager冲突
- 《Android开发艺术》读书笔记之Activity的生命周期和启动
- adb命令
- sdk manager更新失败
- Android TextView 加滚动条
- android:windowSoftInputMode属性
- Android组件式开发(2)——实现网格布局的RadioButton矩阵
- Android LayoutInflate的基本知识
- Android基础之本地广播及文件存储和SharedPreference存储
- Android ActionBar使用
- 常用Android工具类
- [Android]我对View的认识
- android mvp快速开发框架介绍(dileber使用之小工具使用)
- 新浪微博Android-SDK分享网页功能
- Android中的NavigationDrawer的分析
- Android 中的 ContentProvider
- ListView学习(二)-ListView缓存机制
- 为ViewPager添加适配器
- android mvp快速开发框架介绍(继续dileber)
- Android基础_3 Activity相对布局