Brindis personalizado de Android con iconos para modificar la ubicación

Primero en las representaciones de la solicitud 

Código:

 

public class ToastUtil { 


    brindis vacío estático público (String s) { 
        Toast.makeText (context, s, Toast.LENGTH_SHORT) .show (); 
    } 


    TextView estático privado mTextView; 
    ImageView estático privado mImageView; 

    public static void showToast (String message, int imag) { 
        // 加载 Toast 布局
        Ver toastRoot = LayoutInflater.from (context) .inflate (R.layout.toast, null); 
        // 初始化 布局 控件
        mTextView = (TextView) toastRoot.findViewById (R.id.message); 
        mImageView = (ImageView) toastRoot.findViewById (R.id.imageView); 
        // 为 控件 设置 属性
        mTextView.setText (mensaje); 
        si (imag == 0) {
            mImageView.setVisibility (View.GONE); 
        } else { 
            mImageView.setImageResource (imag); 
        } 

        // Inicialización de 
        Toast Toast toastStart = new Toast (contexto); 
        // Obtener altura de pantalla 
        WindowManager wm = (WindowManager) context.getSystemService (Context) .WINDOW_SERVICE); 
        int height = wm.getDefaultDisplay (). GetHeight (); 
        // La coordenada Y de Toast es 1/3 de la altura de la pantalla, por lo que no habrá problemas de 
        desajuste toastStart.setGravity (Gravity.TOP, 0, height / 4); 
        toastStart.setDuration (Toast.LENGTH_SHORT); 
        toastStart.setView (toastRoot); 
        toastStart.show (); 
    } 
}

utilizar:

if (objectBaseArrayBean.getCode (). equals ("200")) { 
    v.updateLastEquipmentSuccess (); 
    ToastUtil.showToast (objectBaseArrayBean.getMessage (), R.mipmap.success_icon); 
} else { 
    ToastUtil.showToast (objectBaseArrayBean.getMessage (), R.mipmap.error_icon); 
}

 

Notas personales. Los comentarios no están detallados.

 

Supongo que te gusta

Origin blog.csdn.net/qq_36355271/article/details/92617616
Recomendado
Clasificación