Skip to content
This repository has been archived by the owner on Oct 23, 2020. It is now read-only.

Customize progressbar width with XML or java #169

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ Here are all the **FloatingActionButton**'s xml attributes with their **default
app:fab_progress_indeterminate="false"
app:fab_progress_max="100"
app:fab_progress="0"
app:fab_progress_showBackground="true"/>
app:fab_progress_showBackground="true"
app:fab_progress_width="6dp"/>
```
All of these **FloatingActionButton**'s attributes has their corresponding getters and setters. So you can set them **programmatically**.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) {
mProgressBackgroundColor = attr.getColor(R.styleable.FloatingActionButton_fab_progress_backgroundColor, 0x4D000000);
mProgressMax = attr.getInt(R.styleable.FloatingActionButton_fab_progress_max, mProgressMax);
mShowProgressBackground = attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_showBackground, true);
mProgressWidth = attr.getDimensionPixelSize(R.styleable.FloatingActionButton_fab_progress_width, mProgressWidth);

if (attr.hasValue(R.styleable.FloatingActionButton_fab_progress)) {
mProgress = attr.getInt(R.styleable.FloatingActionButton_fab_progress, 0);
Expand Down Expand Up @@ -1124,6 +1125,14 @@ public void setElevation(float elevation) {
}
}

public int getProgressBarWidth() {
return mProgressWidth;
}

public void setProgressBarWidth(float width) {
mProgressWidth = Util.dpToPx(getContext(), width);
}

/**
* Sets the shadow color and radius to mimic the native elevation.
*
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<attr name="fab_progress_max" format="integer" />
<attr name="fab_progress" format="integer" />
<attr name="fab_progress_showBackground" format="boolean" />
<attr name="fab_progress_width" format="dimension" />
</declare-styleable>

<declare-styleable name="FloatingActionMenu">
Expand Down