Skip to content

Added More color features for v1.1.9 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 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
6 changes: 6 additions & 0 deletions ChangeLogs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
**v1.1.9**
- Add attribute 'strokeColor'
- Add attribute 'selectedTextColor'
- Add attribute 'unSelectedTextColor'


**v1.1.8**
- support setEnable
- support attr 'disableColor'
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ A smart switchable button,support multiple tabs. CLICK THE ***STAR*** if it's u
| strokeWidth | dimension | app:strokeWidth="2dp" |
| textSize | dimension | app:textSize="16sp" |
| selectedColor | color/reference | app:selectedColor="@color/red" |
| strokeColor | color/reference | app:strokeColor="@color/red" |
| selectedTextColor | color/reference | app:selectedTextColor="@color/red" |
| unSelectedTextColor | color/reference | app:unSelectedTextColor="@color/red" |
| disableColor | color/reference | app:selectedColor="@color/gray" |
| selectedTab | integer | app:selectedTab="1" |
| switchTabs | reference | app:switchTabs="@array/switch_tabs" |
Expand All @@ -18,7 +21,7 @@ A smart switchable button,support multiple tabs. CLICK THE ***STAR*** if it's u
![](https://github.com/KingJA/SwitchButton/blob/master/img/mark.png)
## Gradle
```xml
compile 'lib.kingja.switchbutton:switchbutton:1.1.8'
implementation 'com.github.hamzaahmedkhan:SwitchButton:v2.0.0'
```

## Usage
Expand All @@ -32,6 +35,9 @@ A smart switchable button,support multiple tabs. CLICK THE ***STAR*** if it's u
app:strokeWidth="1dp"
app:selectedTab="0"
app:selectedColor="#eb7b00"
app:selectedTextColor="#ffffff"
app:strokeColor="#ffffff"
app:unSelectedTextColor="#ffffff"
app:switchTabs="@array/switch_tabs"
app:typeface="DeVinneTxtBT.ttf"
app:textSize="14sp" />
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.1.8
VERSION_NAME=1.1.9
VERSION_CODE=2019011001
COMPILE_SDK_VERSION = 27
BUILD_TOOLS_VERSION = 27.0.3
Expand Down
2 changes: 1 addition & 1 deletion libk-switchbutton/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ publish {
artifactId = 'switchbutton'
userOrg = 'kingja'
groupId = 'lib.kingja.switchbutton'
publishVersion = '1.1.8'
publishVersion = '1.1.9'
desc = 'A smart switchable button,support multiple tabs.'
website = 'https://github.com/KingJA/SwitchButton'
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class SwitchMultiButton extends View {
private float mStrokeRadius;
private float mStrokeWidth;
private int mSelectedColor;
private int mStrokeColor;
private int mSelectedTextColor;
private int mUnSelectedTextColor;
private int mDisableColor;
private float mTextSize;
private int mSelectedTab;
Expand Down Expand Up @@ -99,6 +102,9 @@ private void initAttrs(Context context, AttributeSet attrs) {
mStrokeWidth = typedArray.getDimension(R.styleable.SwitchMultiButton_strokeWidth, STROKE_WIDTH);
mTextSize = typedArray.getDimension(R.styleable.SwitchMultiButton_textSize, TEXT_SIZE);
mSelectedColor = typedArray.getColor(R.styleable.SwitchMultiButton_selectedColor, SELECTED_COLOR);
mStrokeColor = typedArray.getColor(R.styleable.SwitchMultiButton_strokeColor, SELECTED_COLOR);
mSelectedTextColor = typedArray.getColor(R.styleable.SwitchMultiButton_selectedTextColor, SELECTED_COLOR);
mUnSelectedTextColor = typedArray.getColor(R.styleable.SwitchMultiButton_unSelectedTextColor, SELECTED_COLOR);
mDisableColor = typedArray.getColor(R.styleable.SwitchMultiButton_disableColor, DISABLE_COLOR);
mSelectedTab = typedArray.getInteger(R.styleable.SwitchMultiButton_selectedTab, SELECTED_TAB);
String mTypeface = typedArray.getString(R.styleable.SwitchMultiButton_typeface);
Expand All @@ -119,7 +125,7 @@ private void initAttrs(Context context, AttributeSet attrs) {
private void initPaint() {
// round rectangle paint
mStrokePaint = new Paint();
mStrokePaint.setColor(mSelectedColor);
mStrokePaint.setColor(mStrokeColor);
mStrokePaint.setStyle(Paint.Style.STROKE);
mStrokePaint.setAntiAlias(true);
mStrokePaint.setStrokeWidth(mStrokeWidth);
Expand All @@ -131,12 +137,12 @@ private void initPaint() {
// selected text paint
mSelectedTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mSelectedTextPaint.setTextSize(mTextSize);
mSelectedTextPaint.setColor(0xffffffff);
mSelectedTextPaint.setColor(mSelectedTextColor);
mStrokePaint.setAntiAlias(true);
// unselected text paint
mUnselectedTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mUnselectedTextPaint.setTextSize(mTextSize);
mUnselectedTextPaint.setColor(mSelectedColor);
mUnselectedTextPaint.setColor(mUnSelectedTextColor);
mStrokePaint.setAntiAlias(true);
mTextHeightOffset = -(mSelectedTextPaint.ascent() + mSelectedTextPaint.descent()) * 0.5f;
mFontMetrics = mSelectedTextPaint.getFontMetrics();
Expand Down Expand Up @@ -427,6 +433,9 @@ protected Parcelable onSaveInstanceState() {
bundle.putFloat("StrokeWidth", mStrokeWidth);
bundle.putFloat("TextSize", mTextSize);
bundle.putInt("SelectedColor", mSelectedColor);
bundle.putInt("StrokeColor", mStrokeColor);
bundle.putInt("SelectedTextColor", mSelectedTextColor);
bundle.putInt("UnSelectedTextColor", mUnSelectedTextColor);
bundle.putInt("DisableColor", mDisableColor);
bundle.putInt("SelectedTab", mSelectedTab);
bundle.putBoolean("Enable", mEnable);
Expand All @@ -441,6 +450,9 @@ protected void onRestoreInstanceState(Parcelable state) {
mStrokeWidth = bundle.getFloat("StrokeWidth");
mTextSize = bundle.getFloat("TextSize");
mSelectedColor = bundle.getInt("SelectedColor");
mStrokeColor = bundle.getInt("StrokeColor");
mSelectedTextColor = bundle.getInt("SelectedTextColor");
mUnSelectedTextColor = bundle.getInt("UnSelectedTextColor");
mDisableColor = bundle.getInt("DisableColor");
mSelectedTab = bundle.getInt("SelectedTab");
mEnable = bundle.getBoolean("Enable");
Expand Down
3 changes: 3 additions & 0 deletions libk-switchbutton/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<declare-styleable name="SwitchMultiButton">
<attr name="strokeRadius" format="dimension" />
<attr name="strokeWidth" format="dimension" />
<attr name="strokeColor" format="color|reference"/>
<attr name="selectedTextColor" format="color|reference"/>
<attr name="unSelectedTextColor" format="color|reference"/>
<attr name="textSize" format="dimension" />
<attr name="selectedTab" format="integer" />
<attr name="selectedColor" format="color|reference" />
Expand Down