moo*_*cle 136 android progress-bar
我在Android上使用循环进度条.我希望改变这个颜色.我在用
"?android:attr/progressBarStyleLargeInverse"
Run Code Online (Sandbox Code Playgroud)
样式.那么如何改变进度条的颜色.
如何定制风格?此外,风格的定义是什么?
Chi*_*rag 148
在res/drawable文件夹中,输入:
progress.xml<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="360">
<shape
android:shape="ring"
android:innerRadiusRatio="3"
android:thicknessRatio="8"
android:useLevel="false">
<size
android:width="76dip"
android:height="76dip" />
<gradient
android:type="sweep"
android:useLevel="false"
android:startColor="#447a29"
android:endColor="#00ffffff"
android:angle="0"/>
</shape>
</rotate>
Run Code Online (Sandbox Code Playgroud)
设置startColor并endColor根据您的选择.
现在设置progress.xml在ProgressBar背景中.
<ProgressBar
android:id="@+id/ProgressBar01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="@drawable/progress"
/>
Run Code Online (Sandbox Code Playgroud)
Muh*_*s M 133
1.First在资源下的drawable文件夹中创建一个xml文件
名为"progress.xml"
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<size
android:height="76dip"
android:width="76dip" />
<gradient
android:angle="0"
android:endColor="color/pink"
android:startColor="@android:color/transparent"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
Run Code Online (Sandbox Code Playgroud)
2.然后使用下面的代码片段创建一个进度条
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/relativeLayout1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/progress" />
Run Code Online (Sandbox Code Playgroud)
Stu*_*222 114
适用于API 21及更高版本.只需设置indeterminateTint属性即可.喜欢:
android:indeterminateTint="@android:color/holo_orange_dark"
Run Code Online (Sandbox Code Playgroud)
要支持pre-API 21设备:
mProgressSpin.getIndeterminateDrawable()
.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN );
Run Code Online (Sandbox Code Playgroud)
Dad*_*oid 65
您可以使用以下代码以编程方式更改颜色:
ProgressBar v = (ProgressBar) findViewById(R.id.progress);
v.getIndeterminateDrawable().setColorFilter(0xFFcc0000,
android.graphics.PorterDuff.Mode.MULTIPLY);
Run Code Online (Sandbox Code Playgroud)
如果要更改ProgressDialog的进度条颜色,可以使用:
mDilog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
ProgressBar v = (ProgressBar)mDilog.findViewById(android.R.id.progress);
v.getIndeterminateDrawable().setColorFilter(0xFFcc0000,
android.graphics.PorterDuff.Mode.MULTIPLY);
}
});
Run Code Online (Sandbox Code Playgroud)
aik*_*anr 35
要添加到Dato的答案,我发现SRC_ATOP是一个更好的过滤器,因为它更好地支持alpha通道.
ProgressBar v = (ProgressBar) findViewById(R.id.progress);
v.getIndeterminateDrawable().setColorFilter(0xFFcc0000, android.graphics.PorterDuff.Mode.SRC_ATOP);
Run Code Online (Sandbox Code Playgroud)
Gab*_*tti 16
通过材质组件库,您可以使用CircularProgressIndicator以下属性:
indicatorColor
trackColor
<com.google.android.material.progressindicator.CircularProgressIndicator
android:indeterminate="true"
app:trackColor="@color/..."
app:indicatorSize="90dp"
app:indicatorColor="@color/..."
/>
Run Code Online (Sandbox Code Playgroud)
Aks*_*dam 11
要自定义循环ProgressBar,我们需要创建一个indeterminateDrawable来显示自定义进度条
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1">
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false">
<size
android:height="48dip"
android:width="48dip" />
<gradient
android:centerColor="#f96047"
android:centerY="0.50"
android:endColor="#fb9c8d"
android:startColor="#f72d0c"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
Run Code Online (Sandbox Code Playgroud)
我们需要在进度条中包含drawable,如下所示:
<ProgressBar
android:layout_width="wrap_content"
android:layout_centerInParent="true"
style="?android:attr/progressBarStyleLarge"
android:visibility="visible"
android:progressDrawable="@drawable/widget_progressbar"
android:indeterminateDrawable="@drawable/widget_progressbar"
android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)
小智 11
styles.xml
<style name="CircularProgress" parent="Theme.AppCompat.Light">
<item name="colorAccent">@color/yellow</item>
</style>
<ProgressBar
android:layout_width="@dimen/d_40"
android:layout_height="@dimen/d_40"
android:indeterminate="true"
style="@style/Widget.AppCompat.ProgressBar"
android:theme="@style/CircularProgress"/>
Run Code Online (Sandbox Code Playgroud)
Kal*_*glu 11
这对我有用.
<ProgressBar
android:id="@+id/ProgressBar01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="@color/black"/>
Run Code Online (Sandbox Code Playgroud)
小智 10
android:indeterminateTint="@color/yellow"
Run Code Online (Sandbox Code Playgroud)
这对我来说是工作,只需将此行添加到您的progressBar xml代码中
对我来说,主题不适用于accentColor.但它确实适用于colorControlActivated
<style name="Progressbar.White" parent="AppTheme">
<item name="colorControlActivated">@color/white</item>
</style>
<ProgressBar
android:layout_width="@dimen/d_40"
android:layout_height="@dimen/d_40"
android:indeterminate="true"
android:theme="@style/Progressbar.White"/>
Run Code Online (Sandbox Code Playgroud)
看看这个答案:
对我来说,这两行必须在那里才能工作并改变颜色:
android:indeterminateTint="@color/yourColor"
android:indeterminateTintMode="src_in"
Run Code Online (Sandbox Code Playgroud)
PS:但它仅适用于 android 21
<style name="progressColor" parent="Widget.AppCompat.ProgressBar">
<item name="colorControlActivated">@color/colorPrimary</item>
</style>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="250dp"
android:theme="@style/progressColor"
android:layout_height="250dp"
android:layout_centerInParent="true" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
170841 次 |
| 最近记录: |