取本地assets目录下fonts路径下的字体资源
public static Typeface getTypeface(Context context) { Typeface face = Typeface.createFromAsset(context.getAssets(), "fonts/BOD_PSTC.TTF"); return face; }
新建一个popWindow
public static PopupWindow createPopWindow(Context context, int layoutId) { View view = LayoutInflater.from(context).inflate(layoutId, null); PopupWindow pop = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); pop.setOutsideTouchable(false);// 点击外部退出 pop.setFocusable(true); pop.setBackgroundDrawable(new ColorDrawable(-00000));// 必须要这个,不然点击外部无效 pop.update(); return pop; }
锁定EditText,使其不可点击聚焦。解锁EditText,使其可点击聚焦。
/**锁定EditText,使其不可点击聚焦*/ public static void lockEditText(EditText...edts) { if(edts == null) return; for(int i=0;i<edts.length;i++) { edts[i].setFocusableInTouchMode(false); } } /**解锁EditText,使其可点击聚焦*/ public static void unlockEditText(EditText...edts) { if(edts == null) return; for(int i=0;i<edts.length;i++) { edts[i].setFocusableInTouchMode(true); } }
判断字符串是否为数字
/**判断字符串是否为数字----方式1,JAVA自带的函数*/ public static boolean isNumeric1(String str){ for (int i = str.length();--i>=0;){ if (!Character.isDigit(str.charAt(i))){ return false; } } return true; } /**判断字符串是否为数字----方式2,正则表达式*/ public static boolean isNumeric2(String str){ Pattern pattern = Pattern.compile("[0-9]*"); return pattern.matcher(str).matches(); } /**判断字符串是否为数字----方式3,ascii码*/ public static boolean isNumeric3(String str){ for(int i=str.length();--i>=0;){ int chr=str.charAt(i); if(chr<48 || chr>57) return false; } return true; }
检测服务是否正在运行
public static boolean isServiceRunning(Context context, String serviceClassName){ final ActivityManager activityManager = (ActivityManager)context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); final List<RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE); for (RunningServiceInfo runningServiceInfo : services) { if (runningServiceInfo.service.getClassName().equals(serviceClassName)){ return true; } } return false; }
判断ip和port是否有效
public static boolean isIpAddress(String ip, String port) { boolean isAvaliable = false;// 初始为无效 if(isNumeric1(port)) { ip = ip.replace(" ", ""); String[] subStrs = ip.split("\\."); if(subStrs.length == 4) for(int i=0;i<4;i++) if(isNumeric1(subStrs[i])) { int n = Integer.valueOf(subStrs[i]); if(n > -1 && n < 256) isAvaliable = true; } } return isAvaliable; }
时间: 2024-10-21 17:51:36