国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

自定義吐司:

2019-11-09 15:35:50
字體:
來源:轉載
供稿:網友

自定義吐司:

package com.herotculb.qunhaichat.widget;

import android.content.Context; import android.content.res.Resources; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast;

import com.herotculb.qunhaichat.R;

/** * 自定義提示Toast * @author HerotCulb * @E-mail herotculb@live.com * @Createtime 2014-5-10 上午9:19:01 */ public class TipsToast extends Toast {

public TipsToast(Context context) { super(context);}public static TipsToast makeText(Context context, CharSequence text, int duration) { TipsToast result = new TipsToast(context); LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflate.inflate(R.layout.view_tips, null); TextView tv = (TextView) v.findViewById(R.id.tips_msg); tv.setText(text); result.setView(v); // setGravity方法用于設置位置,此處為垂直居中 result.setGravity(Gravity.CENTER_VERTICAL, 0, 0); result.setDuration(duration); return result;}public static TipsToast makeText(Context context, int resId, int duration) throws Resources.NotFoundException { return makeText(context, context.getResources().getText(resId), duration);}public void setIcon(int iconResId) { if (getView() == null) { throw new RuntimeException("This Toast was not created with Toast.makeText()"); } ImageView iv = (ImageView) getView().findViewById(R.id.tips_icon); if (iv == null) { throw new RuntimeException("This Toast was not created with Toast.makeText()"); } iv.setImageResource(iconResId);}@Overridepublic void setText(CharSequence s) { if (getView() == null) { throw new RuntimeException("This Toast was not created with Toast.makeText()"); } TextView tv = (TextView) getView().findViewById(R.id.tips_msg); if (tv == null) { throw new RuntimeException("This Toast was not created with Toast.makeText()"); } tv.setText(s);}

}

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/tips_bg" > <!-- 撐開布局 --> <View android:layout_width="100dp" android:layout_height="100dp" android:layout_centerInParent="true" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:orientation="vertical" > <ImageView android:id="@+id/tips_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="10.0dip" android:gravity="center" /> <TextView android:id="@+id/tips_msg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxWidth="180dip" android:layout_gravity="center" android:gravity="center" android:lineSpacingExtra="3.0dip" android:textColor="#ffffffff" android:textSize="17.0sp" /> </LinearLayout></RelativeLayout>
上一篇:RecyclerView的基本使用

下一篇:MYSQL相關

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 随州市| 德令哈市| 苏尼特右旗| 宜兴市| 青海省| 沿河| 东阿县| 无为县| 中西区| 麻城市| 海盐县| 阜南县| 齐河县| 沅江市| 会同县| 仁寿县| 嘉禾县| 沁源县| 南丹县| 合江县| 普陀区| 通江县| 靖宇县| 札达县| 内乡县| 古蔺县| 昭苏县| 嵊州市| 衢州市| 通海县| 邢台县| 靖江市| 石首市| 达孜县| 曲麻莱县| 佛坪县| 繁峙县| 浮山县| 邹城市| 称多县| 西吉县|