标签:原理 error 分享 pop ble esc else 信息 display
/**
* Make a standard toast that just contains a text view.
*
* @param context The context to use. Usually your {@link android.app.Application}
* or {@link android.app.Activity} object.
* @param text The text to show. Can be formatted text.
* @param duration How long to display the message. Either {@link #LENGTH_SHORT} or
* {@link #LENGTH_LONG}
*
*/
public static Toast makeText(Context context, CharSequence text, int duration) {
Toast result = new Toast(context);
LayoutInflater inflate = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
tv.setText(text);
result.mNextView = v;
result.mDuration = duration;
return result;
}
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/toast_shape" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:gravity="center" > <ImageView android:id="@+id/iv_hint_icon" android:layout_width="35dp" android:layout_height="35dp" android:src="@drawable/pda_failure_icon" android:layout_marginLeft="5dp" /> <TextView android:id="@+id/tv_hint_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:textSize="28sp" android:textColor="#eb4e4e" android:layout_marginLeft="5dp" android:text="上架失败 !" android:layout_toRightOf="@+id/iv_hint_icon" /> <TextView android:id="@+id/tv_check_add_info" android:layout_below="@+id/tv_hint_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:textSize="22sp" android:textColor="#eb4e4e" android:layout_marginTop="20dp" android:layout_marginLeft="5dp" android:text="请细致核对上架信息!" /> </RelativeLayout> </LinearLayout></span>
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?
> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="10dp" /> <solid android:color="#ffffff" /> <stroke android:color="#000000" android:width="2dp"/> <padding android:bottom="30dp" android:left="30dp" android:right="30dp" android:top="30dp" /> </shape></span>
public class PDAToast extends Toast{
/**
* Construct an empty Toast object. You must call {@link #setView} before you
* can call {@link #show}.
*
* @param context The context to use. Usually your {@link Application}
* or {@link Activity} object.
*/
public PDAToast(Context context) {
super(context);
}
public static Toast makeText(Context context,int imgId,CharSequence hintText,boolean showFailure,int duration){
Toast mToast = new Toast(context);
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = mInflater.inflate(R.layout.pda_toast_layout,null);//TODO 设置对话框的布局
ImageView hint_icon = (ImageView) layout.findViewById(R.id.iv_hint_icon);
hint_icon.setImageResource(imgId);
TextView hint = (TextView) layout.findViewById(R.id.tv_hint_text);
hint.setText(hintText);
TextView failure_desc = (TextView) layout.findViewById(R.id.tv_check_add_info);
if(showFailure){
failure_desc.setVisibility(View.VISIBLE);
}else{
failure_desc.setVisibility(View.GONE);
}
mToast.setView(layout);
mToast.setGravity(Gravity.CENTER,0,0);
mToast.setDuration(duration);
return mToast;
}
}
Construct an empty Toast object. You must call {@link #setView} before you
* can call {@link #show}public static Toast makeText(Context context,int imgId,CharSequence hintText,boolean showFailure,int duration)
參数解释:
context:上下文
imgId:显示图片资源
hintText:显示提示信息
showFailure:是否显示错误信息
duration:显示时长
<span style="white-space:pre"> </span> @Override
public void onSuccess(BaseResponseData dataObj, String jsonString) {
PDAToast.makeText(AddActivity.this,R.drawable.pda_success_icon,"上架成功 !",false,Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(int resCode, String msg, String jsonString) {
Log.e("TAG","result:"+resCode +" error desc :"+msg +" response data:"+jsonString);
PDAToast.makeText(AddActivity.this,R.drawable.pda_failure_icon,"上架失败 !",true,Toast.LENGTH_SHORT).show();
}
标签:原理 error 分享 pop ble esc else 信息 display
原文地址:http://www.cnblogs.com/claireyuancy/p/7010902.html