FloatingActionButton.java 文件源码

java
阅读 38 收藏 0 点赞 0 评论 0

项目:mvpChat 作者:
/**
 * 创建内层drawable
 *
 * @param color
 * @param strokeWidth
 * @return
 */
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
    //不描边的话直接返回一个颜色为透明的drawable
    if (!mStrokeVisible) {
        return new ColorDrawable(Color.TRANSPARENT);
    }
    //圆 drawable
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());

    final int bottomStrokeColor = darkenColor(color);//这个暗颜色
    final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);//比bottomStrokeColor透明一半
    final int topStrokeColor = lightenColor(color);//这个亮颜色
    final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);//比topStrokeColor透明一半

    final Paint paint = shapeDrawable.getPaint();
    paint.setAntiAlias(true);//锯齿
    paint.setStrokeWidth(strokeWidth);//描边宽度
    paint.setStyle(Style.STROKE);//描边
    //draws a linear gradient
    shapeDrawable.setShaderFactory(new ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width / 2, 0, width / 2, height,
                    new int[]{topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor},
                    new float[]{0f, 0.2f, 0.5f, 0.8f, 1f},
                    TileMode.CLAMP
            );
        }
    });

    return shapeDrawable;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号