如何定义好看的Toast:
一.工具类
package utils;
import com.example.minimalist_telephone.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class ToastUtils {
public static Toast mToast;
public static void SetToast(Context context, String text) {
if (mToast == null) {
mToast = new Toast(context);
}
LayoutInflater inflate = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflate.inflate(R.layout.toast_view, null);
TextView tv_text = (TextView) view.findViewById(R.id.tv_text);
if (text.equals(null)) {
tv_text.setText("");
} else {
tv_text.setText(text);
}
mToast.setView(view);
mToast.setDuration(Toast.LENGTH_SHORT);
mToast.show();
}
}
二.引入的xml文件