|
| 1 | +# LoadingButton [](https://jitpack.io/#FlodCoding/LoadingButton) |
| 2 | + |
| 3 | + 一个小巧灵活的带加载功能的按钮控件,继承自[DrawableTextView]() |
| 4 | + |
| 5 | +## 特性 |
| 6 | + * 支持按钮收缩 |
| 7 | + * 支持加载取消,加载完成和失败图标替换 |
| 8 | + * 可设置加载动画颜色、大小、位置 |
| 9 | + |
| 10 | +## 如何导入 |
| 11 | + |
| 12 | +根目录下的build.gradle |
| 13 | + |
| 14 | + allprojects { |
| 15 | + repositories { |
| 16 | + ... |
| 17 | + maven { url 'https://jitpack.io' } |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + |
| 22 | + App目录下的build.gradle |
| 23 | + |
| 24 | + dependencies { |
| 25 | + implementation 'com.github.FlodCoding:LoadingButton:1.0.0-alpha1' |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | +## Demo |
| 30 | +[点我下载](https://github.com/FlodCoding/LoadingButton/raw/master/app/build/outputs/apk/debug/app-debug.apk) |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +### Demo截图 |
| 35 | +     |
| 36 | + |
| 37 | +## 基本用法 |
| 38 | + |
| 39 | +### XML |
| 40 | +``` |
| 41 | +<com.flod.loadingbutton.LoadingButton |
| 42 | + android:layout_width="match_parent" |
| 43 | + android:layout_height="wrap_content" |
| 44 | + android:background="@drawable/selector_btn" |
| 45 | + android:drawablePadding="10dp" |
| 46 | + android:gravity="center" |
| 47 | + android:padding="8dp" |
| 48 | + android:text="Submit" |
| 49 | + app:endCompleteDrawable="@drawable/ic_successful" |
| 50 | + app:endFailDrawable="@drawable/ic_fail" /> |
| 51 | +``` |
| 52 | +### Code |
| 53 | +``` |
| 54 | +loadingBtn.setEnableShrink(true) |
| 55 | + .setDisableClickOnLoading(true) |
| 56 | + .setShrinkDuration(450) |
| 57 | + .setLoadingColor(loadingBtn.getTextColors().getDefaultColor()) |
| 58 | + .setLoadingStrokeWidth((int) (loadingBtn.getTextSize() * 0.14f)) |
| 59 | + .setLoadingPosition(DrawableTextView.POSITION.START) |
| 60 | + .setCompleteDrawable(R.drawable.ic_successful) |
| 61 | + .setFailDrawable(R.drawable.ic_fail) |
| 62 | + .setEndDrawableKeepDuration(900) |
| 63 | + .setLoadingEndDrawableSize((int) (loadingBtn.getTextSize() * 2)) |
| 64 | + .setOnLoadingListener(new LoadingButton.OnLoadingListenerAdapter() { |
| 65 | + @Override |
| 66 | + public void onCanceled() { |
| 67 | + Toast.makeText(getApplicationContext(), "onCanceled", Toast.LENGTH_SHORT).show(); |
| 68 | + } |
| 69 | +
|
| 70 | + @Override |
| 71 | + public void onFailed() { |
| 72 | + Toast.makeText(getApplicationContext(), "onFailed", Toast.LENGTH_SHORT).show(); |
| 73 | + } |
| 74 | +
|
| 75 | + @Override |
| 76 | + public void onCompleted() { |
| 77 | + Toast.makeText(getApplicationContext(), "onCompleted", Toast.LENGTH_SHORT).show(); |
| 78 | + } |
| 79 | +
|
| 80 | + @Override |
| 81 | + public void onLoadingStart() { |
| 82 | + loadingBtn.setText("Loading"); |
| 83 | + } |
| 84 | +
|
| 85 | + @Override |
| 86 | + public void onEndDrawableAppear(boolean isComplete, LoadingButton.EndDrawable endDrawable) { |
| 87 | + if (isSuccess) { |
| 88 | + loadingBtn.setText("Complete); |
| 89 | + } else { |
| 90 | + loadingBtn.setText("Fail"); |
| 91 | + } |
| 92 | + } |
| 93 | + }); |
| 94 | +``` |
| 95 | + |
| 96 | +## 属性说明 |
| 97 | +属性名|类型|说明 |
| 98 | +---|:--:|---: |
| 99 | +enableShrink |boolean (default:true) |设置加载时收缩 |
| 100 | +disableClickOnLoading |boolen (default:true) |设置加载时禁用点击 |
| 101 | +shrinkDuration |integer (default:450ms) |收缩动画时间 |
| 102 | +loadingEndDrawableSize |dimension (default:TextSize \*2) |设置LaodingDrawable和EndDrawable大小 |
| 103 | +loadingDrawableColor |color (default:TextColor) |设置Loading的颜色 |
| 104 | +loadingDrawablePosition |enum:Start,Top,End,Bottom (default:Start) |设置Loading的位置 |
| 105 | +endCompleteDrawable |reference |完成时显示的图标 |
| 106 | +endFailDrawable |reference |失败时显示的图标 |
| 107 | +endDrawableAppearTime |integer |完成或失败图标从无到有的时间 |
| 108 | +endDrawableDuration |integer |完成或失败图标停留的时间 |
| 109 | + |
| 110 | +## Demo使用的第三方库 |
| 111 | + |
| 112 | +### [Matisse](https://github.com/zhihu/Matisse) |
| 113 | + |
| 114 | +### [Glide](https://github.com/bumptech/glide) |
0 commit comments