购物车加减控件

来源:互联网 发布:淘宝模特余露 编辑:程序博客网 时间:2024/05/03 18:45

Android-ShoppingCartAddSubtract

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

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

运行效果

使用步骤

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);@Overridepublic void onValueChange(View view ,int value) {    switch (view.getId()){        case R.id.stepper:            tvValue.setText(String.valueOf(value));            break;    }}

  • 注意细节

支持更多的自定义属性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);

欢迎关注微信公众号

0 0