-
Notifications
You must be signed in to change notification settings - Fork 3
Number Counter
DV Infosys edited this page Jul 16, 2019
·
1 revision
An amazingly simple and easy-to-use library for your counter (or number picker) needs! It started as a Ctrl-C, Ctrl-V code between my projects and now I've decided to make it into a open-source library!
- In XML layout:
<com.dvinfosys.widgets.NumberCounter.Counter
android:id="@+id/number_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
app:displayAsInteger="true"
app:initialValue="16"
app:maxValue="100"
app:minValue="1"
app:minusButtonColor="#D50000"
app:plusButtonColor="#4CAF50"
app:stepValue="1"
app:textColor="@color/color_blue"
app:textSize="12dp" />
- In Java:
// Params customization:
counter.setStepValue(0.01);
counter.setMaxValue(100.0);
counter.setMinValue(-100.0);
counter.setCurrentValue(1.0);
// If you want to display as integer just do this:
// counter.setDisplayingInteger(true)
// View customization:
counter.setTextColor(Color.parseColor("#4CAF50"));
counter.setMinusIcon(getDrawable(R.drawable.ic_minus));
counter.setMinusButtonColor(Color.parseColor("#909090"));
counter.setPlusIcon(getDrawable(R.drawable.ic_plus));
counter.setPlusButtonColor(Color.parseColor("#909090"));
counter.setTextSize(16);
// Custom action on release:
counter.setOnReleaseListener(() -> {
Toast.makeText(this, "Value updated to: " + counter.getCurrentValue(), Toast.LENGTH_SHORT).show();
});
Copyright (C) 2019 DV Infosys
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.