所有技術文章裡面全部配置了配套視訊
阿新 • • 發佈:2019-02-10
Android-ShoppingCartAddSubtract
一種漂亮的UI控制元件,能更靈活的控制數字的增減。
執行效果
使用步驟
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; } }
- 注意細節
支援更多的自定義屬性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);
歡迎關注微信公眾號