下面列出了android.widget.ProgressBar#setIndeterminateTintList ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_confirm, menu);
ProgressBar pb = new ProgressBar(this);
MenuItem progressItem = menu.findItem(R.id.menu_confirm_progress);
int px = (int) (24 * Resources.getSystem().getDisplayMetrics().density);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(3*px, 3*px);
pb.setLayoutParams(lp);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
pb.setIndeterminateTintList(
ColorStateList.valueOf(0xff000000)
);
}
pb.setPaddingRelative(px, px, px, px);
progressItem.setActionView(pb);
return true;
}
public TextView showProgressDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
View view = View.inflate(this, R.layout.dialog_loading, null);
builder.setView(view);
ProgressBar pb_loading = (ProgressBar) view.findViewById(R.id.pb_loading);
TextView tv_hint = (TextView) view.findViewById(R.id.tv_hint);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
pb_loading.setIndeterminateTintList(ContextCompat.getColorStateList(this, R.color.blue));
}
progressDialog = builder.create();
progressDialog.show();
return tv_hint;
}
public static void tint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
ColorStateList sl = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressBar.setProgressTintList(sl);
progressBar.setSecondaryProgressTintList(sl);
if (!skipIndeterminate)
progressBar.setIndeterminateTintList(sl);
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
if (progressBar.getProgressDrawable() != null)
progressBar.getProgressDrawable().setColorFilter(color, mode);
}
}
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
ColorStateList sl = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressBar.setProgressTintList(sl);
progressBar.setSecondaryProgressTintList(sl);
if (!skipIndeterminate)
progressBar.setIndeterminateTintList(sl);
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
if (progressBar.getProgressDrawable() != null)
progressBar.getProgressDrawable().setColorFilter(color, mode);
}
}
@SuppressLint("NewApi")
public static void setTint(ProgressBar progressBar, int color, boolean skipIndeterminate) {
ColorStateList sl = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressBar.setProgressTintList(sl);
progressBar.setSecondaryProgressTintList(sl);
if (!skipIndeterminate)
progressBar.setIndeterminateTintList(sl);
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
if (progressBar.getProgressDrawable() != null)
progressBar.getProgressDrawable().setColorFilter(color, mode);
}
}
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color,
boolean skipIndeterminate) {
ColorStateList sl = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressBar.setProgressTintList(sl);
progressBar.setSecondaryProgressTintList(sl);
if (!skipIndeterminate) {
progressBar.setIndeterminateTintList(sl);
}
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null) {
progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
}
if (progressBar.getProgressDrawable() != null) {
progressBar.getProgressDrawable().setColorFilter(color, mode);
}
}
}
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
ColorStateList sl = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressBar.setProgressTintList(sl);
progressBar.setSecondaryProgressTintList(sl);
if (!skipIndeterminate)
progressBar.setIndeterminateTintList(sl);
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
if (progressBar.getProgressDrawable() != null)
progressBar.getProgressDrawable().setColorFilter(color, mode);
}
}
@Override
protected void setAttr(final ProgressBar view, final int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.setIndeterminateTintList(ColorStateList.valueOf(color));
}
else {
DrawableCompat.setTint(view.getIndeterminateDrawable(), color);
}
}
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
ColorStateList sl = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressBar.setProgressTintList(sl);
progressBar.setSecondaryProgressTintList(sl);
if (!skipIndeterminate)
progressBar.setIndeterminateTintList(sl);
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
if (progressBar.getProgressDrawable() != null)
progressBar.getProgressDrawable().setColorFilter(color, mode);
}
}
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
ColorStateList sl = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressBar.setProgressTintList(sl);
progressBar.setSecondaryProgressTintList(sl);
if (!skipIndeterminate)
progressBar.setIndeterminateTintList(sl);
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
if (progressBar.getProgressDrawable() != null)
progressBar.getProgressDrawable().setColorFilter(color, mode);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_loading, container, false);
FrameLayout loadingContainer = (FrameLayout) view.findViewById(R.id.fragment_loading_container);
loadingContainer.setBackgroundColor(backgroundColor);
progressBar = new ProgressBar(container.getContext());
if (container instanceof FrameLayout) {
FrameLayout.LayoutParams layoutParams =
new FrameLayout.LayoutParams(progressWidth, progressHeight, Gravity.CENTER);
progressBar.setLayoutParams(layoutParams);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
if (progressBar.getIndeterminateDrawable() != null) {
progressBar.getIndeterminateDrawable().setColorFilter(getResources().getColor(progressColor),
PorterDuff.Mode.SRC_IN);
}
} else {
ColorStateList stateList = ColorStateList.valueOf(progressColor);
progressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN);
progressBar.setIndeterminateTintList(stateList);
progressBar.setProgressBackgroundTintMode(PorterDuff.Mode.SRC_IN);
progressBar.setProgressBackgroundTintList(stateList);
progressBar.setIndeterminate(true);
}
loadingContainer.addView(progressBar);
return view;
}
@Override
public View createProgressView() {
mProgressBar = new ProgressBar(mContext);
mProgressBar.setLayoutParams(new ViewGroup.LayoutParams(mLoadingSize, mLoadingSize));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& mIndeterminateDrawable == null) {
mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(mLoadingColor));
}
if (mIndeterminateDrawable != null) {
mProgressBar.setIndeterminateDrawable(mIndeterminateDrawable);
}
return mProgressBar;
}
private void initView(BaseViewHolder holder) {
if (holder == null) {
return;
}
holder.setText(R.id.tv_loadingFastLoadMore, mLoadingText)
.setTextColor(R.id.tv_loadingFastLoadMore, mLoadingTextColor)
.setText(R.id.tv_loadFailFastLoadMore, mLoadFailText)
.setTextColor(R.id.tv_loadFailFastLoadMore, mLoadFailTextColor)
.setText(R.id.tv_loadEndFastLoadMore, mLoadEndText)
.setTextColor(R.id.tv_loadEndFastLoadMore, mLoadEndTextColor);
TextView tvLoading = holder.getView(R.id.tv_loadingFastLoadMore);
TextView tvLoadFail = holder.getView(R.id.tv_loadFailFastLoadMore);
TextView tvLoadEnd = holder.getView(R.id.tv_loadEndFastLoadMore);
ProgressBar pbLoading = holder.getView(R.id.pb_loadingFastLoadMore);
tvLoading.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLoadingTextSize);
tvLoading.getPaint().setFakeBoldText(mLoadingTextFakeBold);
tvLoadFail.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLoadFailTextSize);
tvLoadFail.getPaint().setFakeBoldText(mLoadFailTextFakeBold);
tvLoadEnd.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLoadEndTextSize);
tvLoadEnd.getPaint().setFakeBoldText(mLoadEndTextFakeBold);
if (mLoadingSize >= 0) {
pbLoading.getIndeterminateDrawable().setBounds(0, 0, mLoadingSize, mLoadingSize);
ViewGroup.LayoutParams params = pbLoading.getLayoutParams();
params.width = mLoadingSize;
params.height = mLoadingSize;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
pbLoading.setIndeterminateTintList(ColorStateList.valueOf(mLoadingProgressColor));
}
if (mLoadingProgressDrawable != null) {
mLoadingProgressDrawable.setBounds(pbLoading.getIndeterminateDrawable().getBounds());
pbLoading.setIndeterminateDrawable(mLoadingProgressDrawable);
}
}
@Override
public void applyColor(ProgressBar view, @ColorInt int color) {
view.setIndeterminateTintList(Utils.colorToStateList(color));
}