美文网首页
android 工具类,及方法

android 工具类,及方法

作者: Android砖家 | 来源:发表于2019-03-05 16:10 被阅读0次

    1.产生shape类型的drawable,再也不用写一堆的shape了
     /**
         * 产生shape类型的drawable
         * @param solidColor    填充的颜色
         * @param strokeColor   描边的颜色
         * @param strokeWidth   描边的大小
         * @param radius        圆角的度数
         * @return
         */
        public static GradientDrawable getBackgroundDrawable(int solidColor, int strokeColor, int strokeWidth, float radius) {
            GradientDrawable drawable = new GradientDrawable();
            drawable.setColor(solidColor);
            drawable.setStroke(strokeWidth, strokeColor);
            drawable.setCornerRadius(radius);
            return drawable;
        }
    //这个方法功能更加强大
     /**
         * 1、2两个参数表示左上角,3、4表示右上角,5、6表示右下角,7、8表示左下角
         * @param solidColor
         * @param strokeColor
         * @param strokeWidth
         * @param topLeftRadius
         * @param topRightRadius
         * @param bottomRightRadius
         * @param bottomLeftRadius
         * @return
         */
        public static GradientDrawable getBackgroundDrawable1(int solidColor, int strokeColor, int strokeWidth, float topLeftRadius, float topRightRadius
                , float bottomRightRadius, float bottomLeftRadius) {
            GradientDrawable drawable = new GradientDrawable();
            drawable.setColor(solidColor);
            drawable.setStroke(strokeWidth, strokeColor);
            drawable.setCornerRadii(new float[]{
                    topLeftRadius,
                    topLeftRadius,
                    topRightRadius,
                    topRightRadius,
                    bottomRightRadius,
                    bottomRightRadius,
                    bottomLeftRadius,
                    bottomLeftRadius});
            return drawable;
        }
    
    

    2.字体颜色选择器Selector
     /**
         *  颜色点击选择器 selector 
         * @param intnormal   默认颜色
         * @param intchecked  点击时的颜色
         * @return
         */
        public static ColorStateList getTextColorSelector(int intnormal, int intchecked){
            int[][] states = new int[2][];
            states[0] =  new int[]{android.R.attr.state_pressed};
            states[1] = new int[]{};
            int[] colors = new int[]{intchecked,intnormal};
            ColorStateList csl = new ColorStateList(states,colors);
            return csl;
        }
    

    3.动态改变textTexview Hint显示的大小,但不影响字体大小
        /**
         * 动态改变textTexview Hint显示的大小,但不影响字体大小
         * @param hintMsg
         * @return
         */
    
        public static CharSequence getTextHint(String hintMsg) {
            SpannableString ss = new SpannableString(hintMsg);//定义hint的值
            AbsoluteSizeSpan ass = new AbsoluteSizeSpan(15, true);//设置字体大小 true表示单位是sp
            ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            return new SpannedString(ss);
        }
    

    相关文章

      网友评论

          本文标题:android 工具类,及方法

          本文链接:https://www.haomeiwen.com/subject/tzlouqtx.html