自定义Toast样式-两行文本居中显示
toast可以设置自定义的view和显示位置。下面是一个简单的例子,复杂些的就是改变其布局文件就可以了。
/**
* @author BMR
* @ClassName: ToastWithTwoText
* @Description: TODO:
* @date 2015/12/22 14:24
*/
public class ToastWithTwoText {
private static ToastWithTwoText toastWithTwoText; private Toast toast;
private Context mContext; private ToastWithTwoText(Context context) {
this.mContext = context;
} public static ToastWithTwoText createToastConfig(Context context) {
if (toastWithTwoText == null) {
toastWithTwoText = new ToastWithTwoText(context);
}
return toastWithTwoText;
} /**
* 显示Toast
*
* @param tvStrOne
* @param tvStrTwo
*/ public void ToastShow(String tvStrOne, String tvStrTwo) {
View layout = LayoutInflater.from(mContext).inflate(R.layout.layout_toast_with_two_text, null);
TextView tvOne = (TextView) layout.findViewById(R.id.tv_text_one);
TextView tvTwo = (TextView) layout.findViewById(R.id.tv_text_two);
tvOne.setText(tvStrOne);
tvTwo.setText(tvStrTwo);
toast = new Toast(mContext);
toast.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
} public void ToastShow(int idStrOne, int idStrTwo) {
ToastShow(mContext.getString(idStrOne), mContext.getString(idStrTwo));
} }
布局文件代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="@dimen/common_16"
android:paddingRight="@dimen/common_16"
android:background="@drawable/bg_circle_cornor_rect"
android:orientation="vertical"> <TextView
android:id="@+id/tv_text_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/common_16"
android:gravity="center"
android:textColor="@color/trans_white2"
android:textSize="16dp"/> <TextView
android:id="@+id/tv_text_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/common_16"
android:gravity="center"
android:textColor="@color/trans_white2"
android:textSize="16dp"/> </LinearLayout>
圆角背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/trans_black_87" />
<corners android:topLeftRadius="8dp"
android:topRightRadius="8dp"
android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"/>
</shape>
资源字段
<color name="trans_black_87">#DD000000</color> <!-- 87% trans -->
<color name="trans_white2">#ccffffff</color>
<dimen name="common_16">16dp</dimen>
自定义Toast样式-两行文本居中显示的更多相关文章
- 重写TextView,实现圆形背景,文本居中显示
最近,在做考试试题排版,产品提出题号希望显示成圆形背景,序号文本居中显示. (有点问题:文本没有绝对居中,暂时没做处理.) 为此,我采取的方式是重写TextView的onDraw方法,绘制一个圆形背景 ...
- CSS文本居中显示
因为一直为元素居中问题而困扰,所以决定把自己遇到和看到的方法记录下来,以便以后查看 如果要让inline或inline-block元素居中显示,则父元素css中包含text-align:center; ...
- flex的Accordion组件头部文本居中显示
flex的Accordion组件头部文本默认是居左的,可以通过设置headerStyleName属性使之居中,另外还可以设置字体的样式等 <?xml version="1.0" ...
- ExtJS -- Grid 文本居中显示
Reference: http://stackoverflow.com/questions/6561120/extjs-4-apply-defaults-to-all-columns-in-a-gri ...
- LabelControl文本居中显示
https://www.devexpress.com/Support/Center/Question/Details/Q94915 If you set the AutoSizeMode to Non ...
- css 单行文本居中显示,多行文本左对齐
父级元素 text-align:center; 自级元素 text-align:left; display:inline-block;
- ToastUtil【简单的Toast封装类】【未自定义Toast的显示风格】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 一个简单的Toast封装类. 效果图 API = 6.0 API = 4.4.2 代码分析 实现了不管我们触发多少次Toast调用, ...
- ToastCustomUtil【简单的Toast封装类】【自定义Toast的显示风格】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 ToastUtil + ToastCustom结合.主要解决低版本机型上系统toast显示不好看的问题. 效果图 代码分析 在Toa ...
- 自定义Toast的显示位置和显示内容
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
随机推荐
- CentoS6.x网络配置
一.配置文件 在CentoS系统里面,跟网络有关的主要配置文件有 1./etc/host.conf # 配置域名服务客户端的控制文件 2./etc/hosts # 配置主机名映射为IP的功能 3 ...
- 专题开发十三:JEECG微云高速开发平台-附录
专题开发十三:JEECG微云高速开发平台-附录 12.1UI库经常使用控件參考演示样例 序号 控件 解决方式 參考演示样例 1 datagrid数据列表.字段採用数据字典显示文本 <t:dgCo ...
- CheckBoxPreference组件
CheckBoxPreference 选中为true 取消选中为false 它的值会以boolean的形式储存在SharedPreferences中. <?xml version="1 ...
- [LeetCode] Search in Rotated Sorted Array [35]
题目 Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 m ...
- 绿色mysql启动脚本
启动脚本如下:./mysqld_safe --defaults-file=/export/servers/mysql-5.5.38/my.cnf --ledir=/export/servers/mys ...
- ADO.Net两种访问数据库模式
在连接模式下的数据库访问通常包括以下几个步骤: 1.通过数据库连接类(DbConnection)链接类指定到数据库服务器的数据库 2.通过数据库命令类(DbCommand)在数据库上执行SQL命令,可 ...
- MVC3学习随记一
最近才接触mvc,也是才接触linq语法,还有EntiyFramework,个人感觉这种开发模式还是挺不错的,随手记点笔记,简单做个增删改查吧 一.实例化上下文ObjectContext: 引用空间那 ...
- APP安全测评checklist
leader不要打我啊,我要借用一下我组app的安全测评检查方案,这些最基本的安全防范措施应该是每个app都要注意的吧: 对了,首先,你的app得先混淆啊~:AndroidStudio 混淆打包 先来 ...
- javac编译原理(一)
我们都知道,计算机只能识别二进制语言,是不能直接识别java c c++等高级语言的.将高级语言转化成计算机可以是别的二进制语言,这个过程就叫编译. 有次面试,面试官问了一道“java的编译原理是什么 ...
- 修改已经提交到远端的git commit信息
有这么一种场景,就是以前没有设置用户名和邮箱,导致提交时git commit信息中用户信息不正确.这样的情况导致后来我们提交代码到git上面时因为身份验证错误,只有到 push 阶段了才发现提交不上去 ...