[英]Changing the indicator color in a Snackbar
我在我的应用程序中使用此库:
实施'com.wang.avi:library:2.1.3'
我想自定义一个Snackbar ,并向其添加TextView和ProgressBar 。 我的代码是这样的:
Snackbar loadingSnackBar = Snackbar.make(getActivity().getWindow().getDecorView().findViewById(R.id.main_viewpager), R.string.loading, Snackbar.LENGTH_INDEFINITE);
TextView tv = loadingSnackBar.getView().findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.BLACK);
loadingSnackBar.getView().setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));
ViewGroup contentLay = (ViewGroup) tv.getParent();
AVLoadingIndicatorView indicator = new AVLoadingIndicatorView(getContext());
indicator.setIndicator("BallPulseIndicator");
indicator.setIndicatorColor(R.color.orange);
contentLay.addView(indicator, 100, 100);
Snackbar可通过TextView和ProgressBar正确显示,但指示器的颜色为紫色,而不是橙色。 如何将指示器的颜色更改为橙色?
我无法以编程方式更改颜色。 所以我这样创建my_indicator.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.wang.avi.AVLoadingIndicatorView
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="14dp"
app:indicatorName="BallPulseIndicator"
app:indicatorColor="@color/orange"/>
</android.support.constraint.ConstraintLayout>
然后像这样将其添加到我的Snackbar中:
View snackView = inflater.inflate(R.layout.test, null);
contentLay.addView(snackView);
这样可以,但是如果您能找到以编程方式更改颜色的解决方案,请告诉我!
您能否通过切换顺序来尝试:
indicator.setIndicatorColor(R.color.orange);
indicator.setIndicator("BallPulseIndicator");
另外,“ app:indicatorColor”可以设置颜色
<com.wang.avi.AVLoadingIndicatorView
android:id="@+id/avi"
android:layout_width="wrap_content" //or your custom size
android:layout_height="wrap_content" //or your custom size
style="@style/AVLoadingIndicatorView"// or AVLoadingIndicatorView.Large or AVLoadingIndicatorView.Small
android:visibility="visible" //visible or gone
app:indicatorName="BallPulseIndicator"//Indicator Name
app:indicatorColor="your color"
/>
更换
indicator.setIndicatorColor(R.color.orange);
上
indicator.setIndicatorColor(ContextCompat.getColor(context,R.color.orange));
一切都会正常! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.