Giter Club home page Giter Club logo

shoppingcartaddsubtract's Introduction

Android-ShoppingCartAddSubtract

一种漂亮的UI控件,能更灵活的控制数字的增减。

项目地址:https://github.com/open-android/ShoppingCartAddSubtract

简书:http://www.jianshu.com/p/be3d0f763c5a

运行效果

  • 爱生活,爱学习,更爱做代码的搬运工,分类查找更方便请下载黑马助手app

黑马助手.png

使用步骤

1. 在project的build.gradle添加如下代码(如下图)

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

2. 在Module的build.gradle添加依赖

 compile 'com.github.open-android:ShoppingCartAddSubtract:0.1.0'

3. 在XML添加如下代码

<LinearLayout
    android:padding="15dp"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.bigkoo.snappingstepper.SnappingStepper
        android:id="@+id/stepper"
        android:layout_width="120dp"
        android:layout_height="30dp"/>

    <TextView
        android:id="@+id/tvValue"
        android:layout_marginLeft="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

4. 在java类中添加如下代码

tvValue = (TextView) findViewById(R.id.tvValue);
stepper = (SnappingStepper) findViewById(R.id.stepper);
tvValue.setText(String.valueOf(stepper.getValue()));
stepper.setOnValueChangeListener(this);
@Override
public void onValueChange(View view ,int value) {
    switch (view.getId()){
        case R.id.stepper:
            tvValue.setText(String.valueOf(value));
            break;
    }
}

  • 注意细节

支持更多的自定义属性XML表示

<com.bigkoo.snappingstepper.SnappingStepper
  android:id="@+id/stepperCustom2"
  stepper:max="200"
  stepper:min="50"
  stepper:step="5"
  stepper:value="100"
  android:layout_width="150dp"
  android:layout_height="40dp"
  stepper:stepper_background="@color/colorStepperButtonNormal"
  stepper:stepper_leftButtonBackground="@drawable/sl_steppercustom_button_bg"
  stepper:stepper_rightButtonBackground="@drawable/sl_steppercustom_button_bg"
  stepper:stepper_contentBackground="@color/colorStepperContentBg"
  stepper:stepper_contentTextColor="#0099ff"
  stepper:stepper_contentTextSize="18"
  stepper:stepper_leftButtonResources="@drawable/ic_stepper_left"
  stepper:stepper_rightButtonResources="@drawable/ic_stepper_right"
  />

支持更多的自定义属性java代码表示

stepperCustom.setBackgroundColor(getResources().getColor(R.color.colorStepperButtonNormal));
stepperCustom.setButtonBackGround(R.drawable.sl_steppercustom_button_bg);
stepperCustom.setContentBackground(R.color.colorStepperContentBg);
stepperCustom.setContentTextColor(R.color.colorStepperText);
stepperCustom.setContentTextSize(18);
stepperCustom.setLeftButtonResources(R.drawable.ic_stepper_left);
stepperCustom.setRightButtonResources(R.drawable.ic_stepper_right);
  • 详细的使用方法在DEMO里面都演示啦,如果你觉得这个库还不错,请赏我一颗star吧~~~

  • 欢迎关注微信公众号

shoppingcartaddsubtract's People

Contributors

open-android avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.