53 lines
1.5 KiB
Plaintext
Executable File
53 lines
1.5 KiB
Plaintext
Executable File
package com.cm.utils.uiutils;
|
|
|
|
import android.app.ProgressDialog;
|
|
import android.content.Context;
|
|
import android.os.Handler;
|
|
import android.widget.Toast;
|
|
|
|
/**
|
|
* 提示工具类
|
|
* Created by Xuer on 2017/3/9.
|
|
*/
|
|
public class UIUtil {
|
|
public static void toast(final Context context, final String msg) {
|
|
new Handler(context.getMainLooper()).post(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
|
}
|
|
});
|
|
}
|
|
/**
|
|
* 圆形进度条dialog
|
|
* @param context
|
|
* @param tips
|
|
* @return
|
|
*/
|
|
public static ProgressDialog initDialog(Context context, String tips) {
|
|
ProgressDialog dialog = new ProgressDialog(context);
|
|
dialog.setMessage(tips);
|
|
dialog.setCancelable(true);
|
|
dialog.setCanceledOnTouchOutside(false);
|
|
return dialog;
|
|
}
|
|
|
|
|
|
/**
|
|
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
|
|
*/
|
|
public static int dip2px(Context context, float dpValue) {
|
|
final float scale = context.getResources().getDisplayMetrics().density;
|
|
return (int) (dpValue * scale + 0.5f);
|
|
}
|
|
|
|
/**
|
|
* 根据手机的分辨率从 px(像素) 的单位 转成为 dp
|
|
*/
|
|
public static int px2dip(Context context, float pxValue) {
|
|
final float scale = context.getResources().getDisplayMetrics().density;
|
|
return (int) (pxValue / scale + 0.5f);
|
|
}
|
|
|
|
}
|