当前位置: 代码迷 >> Android >> Android Material Design(1)Floating Action Button
  详细解决方案

Android Material Design(1)Floating Action Button

热度:195   发布时间:2016-04-28 01:57:02.0
Android Material Design(一)Floating Action Button

Android with Material Design .在GitHub上看到的开源库,自己下载下来研究了一下,效果图:
好东西要分享,GitHub下载地址:
Android Floating Action Button

先看一下Floating Action Button类的主要逻辑:
    void init(Context context, AttributeSet attributeSet) {        TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionButton, 0, 0);        mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, getColor(android.R.color.holo_blue_dark));        mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, getColor(android.R.color.holo_blue_light));        mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, getColor(android.R.color.darker_gray));        mSize = attr.getInt(R.styleable.FloatingActionButton_fab_size, SIZE_NORMAL);        mIcon = attr.getResourceId(R.styleable.FloatingActionButton_fab_icon, 0);        mTitle = attr.getString(R.styleable.FloatingActionButton_fab_title);        mStrokeVisible = attr.getBoolean(R.styleable.FloatingActionButton_fab_stroke_visible, true);        attr.recycle();        updateCircleSize();        mShadowRadius = getDimension(R.dimen.fab_shadow_radius);        mShadowOffset = getDimension(R.dimen.fab_shadow_offset);        updateDrawableSize();        updateBackground();    }
主要类方法:
private void updateDrawableSize() {        mDrawableSize = (int) (mCircleSize + 2 * mShadowRadius);    }    private void updateCircleSize() {        mCircleSize = getDimension(mSize == SIZE_NORMAL ? R.dimen.fab_size_normal : R.dimen.fab_size_mini);    }    public void setSize(@FAB_SIZE int size) {        if (size != SIZE_MINI && size != SIZE_NORMAL) {            throw new IllegalArgumentException("Use @FAB_SIZE constants only!");        }        if (mSize != size) {            mSize = size;            updateCircleSize();            updateDrawableSize();            updateBackground();        }    }    @FAB_SIZE    public int getSize() {        return mSize;    }    public void setIcon(@DrawableRes int icon) {        if (mIcon != icon) {            mIcon = icon;            mIconDrawable = null;            updateBackground();        }    }    public void setIconDrawable(@NonNull Drawable iconDrawable) {        if (mIconDrawable != iconDrawable) {            mIcon = 0;            mIconDrawable = iconDrawable;            updateBackground();        }    }    /**     * @return the current Color for normal state.     */    public int getColorNormal() {        return mColorNormal;    }

我在这些地方: CSDN GitHub 微博

  相关解决方案