zoukankan      html  css  js  c++  java
  • 一大波静态方法

    取本地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是否有效

    public static boolean isIpAddress(String ip) {
        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 < 0 && n > 255) return false;
                    } else return false;
         } else return false; }
    return true; }
  • 相关阅读:
    [iOS]Xcode+GitHub远程代码托管(GIT, SVN)
    [iOS]Xcode处理过时方法的警告
    [iOS]@synthesize和@dynamic关键字
    [iOS]图片高清度太高, 导致内存过大Crash
    [软件]Xcode查找系统framework所在路径
    [软件]在浏览器里添加MarkDown Here(插件)
    [PHP]利用XAMPP搭建本地服务器, 然后利用iOS客户端上传数据到本地服务器中(四. iOS端代码实现)
    ios -Unity3D的EasyAR集成到已经有项目中。
    iOS创建安全的单例
    阿里云轻量应用服务器 配置mysql详解(转载)
  • 原文地址:https://www.cnblogs.com/swalka/p/4738177.html
Copyright © 2011-2022 走看看