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; }
  • 相关阅读:
    mysql 5.6
    mysql5.7 二进制包安装
    centos 6 编译安装httpd-2.4
    mysql 5.5源码包安装
    BZOJ4945 & 洛谷3825 & UOJ317:[NOI2017]游戏——题解
    BZOJ4943 & 洛谷3823 & UOJ315:[NOI2017]蚯蚓排队——题解
    BZOJ3435 & 洛谷3920 & UOJ55:[WC2014]紫荆花之恋
    BZOJ5343 & 洛谷4602 & LOJ2555:[CTSC2018]混合果汁——题解
    真·APIO2018滚粗记
    BZOJ4518:[SDOI2016]征途——题解
  • 原文地址:https://www.cnblogs.com/swalka/p/4738177.html
Copyright © 2011-2022 走看看