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

首頁 > 學院 > 開發(fā)設計 > 正文

自定義吐司:

2019-11-09 16:46:33
字體:
供稿:網(wǎng)友

自定義吐司:

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>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 弋阳县| 木兰县| 清涧县| 宜宾市| 阳东县| 浮梁县| 惠来县| 阿拉善盟| 晋江市| 罗江县| 玛曲县| 灵武市| 江达县| 岗巴县| 宣汉县| 茌平县| 突泉县| 奈曼旗| 且末县| 丹寨县| 方正县| 平原县| 张掖市| 洪泽县| 奉节县| 富阳市| 深州市| 元朗区| 海口市| 连江县| 永福县| 育儿| 固始县| 阳新县| 泰安市| 鹤岗市| 六安市| 苍溪县| 绥阳县| 金湖县| 运城市|