一个带ProgressBar的Button,通过自定义ConstraintLayout实现。
maven仓库添加
maven { url "https://raw.githubusercontent.com/laxian/LoadingButton/master" }
依赖添加
implementation 'com.zwx.loadingbutton:loadingbutton:1.0.0'
布局方式:
<com.zwx.loadingbutton.LoadingButton
android:id="@+id/forth"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginBottom="24dp"
android:background="@drawable/mdw_btn_bg_round_gradient_enable_big"
app:pbYesStyle="true"
android:paddingHorizontal="12dp"
app:pbIndeterminateDrawable="@drawable/mdw_progressbar_circle"
app:pbLoadingText="LOGIN"
app:pbProgressColor="#582707"
app:pbProgressLeft="true"
app:pbText="EXACTLY"
app:pbTextColor="#7286A0"
app:pbTextSize="16sp" />
代码方式:
LoadingButton button = new LoadingButton(this);
LoadingButton.ViewSwitcherFactory factory = new LoadingButton.ViewSwitcherFactory(this,
getResources().getColor(android.R.color.white),
44F,
Typeface.DEFAULT);
button.setTextFactory(factory);
button.setProgressBarLeftMode();
button.setText("new LoadingButton()");
button.setLoadingText("wait...");
button.setBackgroundColor(Color.RED);
button.setOnClickListener(this);
button.setPadding(0,20,0,20);
button.setAnimationInDirection(LoadingButton.IN_FROM_LEFT);
((ViewGroup) findViewById(R.id.root)).addView(button);
自定义项 | 说明 |
---|---|
pbText | 文字 |
pbLoadingText | 加载中文字 |
pbTextSize | 文字大小 |
pbTextColor | 文字颜色 |
pbProgressColor | 加载圈颜色 |
pbIndeterminateDrawable | 加载圈图 |
pbYesStyle | 提供一种yes状态,在选择器使用 |
pbWeakStyle | 提供一种若样式,在选择器使用 |
pbProgressSize | 加载圈大小,默认等于文字 |
pbProgressLeft | 加载圈显示在左边,默认右边 |
通过自定义ConstraintLayout实现。
通过RelativeLayout方式的实现,有一些缺陷:
-
宽度为wrap_content时,toEndOf,会出现位置不准。
-
宽度为wrap_content时,内部元素alignParentEnd,会导致wrap_content失效
maven_push.gradle
更新PUBLISH_VERSION
,然后执行:
./gradlew uploadArchives
参考snadjafi