progressBar.BackColor=System.Drawing.Blue
2、在属性窗口设置progressBar的ForeColor属性可以修改前景色,也可以用代码,如:
progressBar.ForeColor=System.Drawing.Red
给你举个例子,是改进度条颜色滴,自己延伸下吧~Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Private Const WM_USER = &H400
Private Const PBM_SETBARCOLOR = (WM_USER + 9)
Private Function SetProgressBarColor(TargetProgressBar As ProgressBar) '进度条的颜色
SendMessage TargetProgressBar.hwnd, PBM_SETBARCOLOR, 0, ByVal RGB(IIf(TargetProgressBar.Value / TargetProgressBar.Max * 255 <255 * 0.5, TargetProgressBar.Value / TargetProgressBar.Max * 255 * 2, 255), IIf(TargetProgressBar.Value / TargetProgressBar.Max * 255 <255 * 0.5, 255, (255 - TargetProgressBar.Value / TargetProgressBar.Max * 255) * 2), 0)
End Function
Private Sub Command1_Click()
If ProgressBar1.Value <ProgressBar1.Max Then
ProgressBar1.Value = ProgressBar1.Value + 10
Else
ProgressBar1.Value = 0
End If
SetProgressBarColor ProgressBar1
End Sub
Private Sub Form_Load()
ProgressBar1.Max = 100
ProgressBar1.Value = 0
End Sub
'自己添加控件试下吧
需求:下载中的颜色要自定义,要替换为另外的一个颜色方法:就是在
<ProgressBar
android:layout_weight="1"
android:id="@+id/download_item_progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="15dip"
android:progressDrawable="@drawable/progressbar_style"></ProgressBar>
在drawable中新建一个progressBar_style.xml文件,
这个属性进行设置,有两个方案:
第一,设置两张图片:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="">
<item android:id="@android:id/background"
android:drawable="@drawable/progressbar_not" />
<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/progressbar_not">
</item>
<item android:id="@android:id/progress"
android:drawable="@drawable/progressbar_selected">
</item>
</layer-list>
第二种,设置背景颜色:
<?xml version="1.0" encoding="utf-8"?>
<item android:id="@android:id/background"
>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#666666"
android:centerColor="#666666"
android:centerY="0.75"
android:endColor="#666666"
android:angle="270"
/>
</shape>
</item>
<item android:id="@android:id/progress"
>
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#da1f3e"
android:centerColor="#da1f3e"
android:centerY="0.75"
android:endColor="#da1f3e"
android:angle="270"
/>
</shape>
</clip>
</item>
<item android:id="@android:id/secondaryProgress"
>
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#fed7ec"
android:centerColor="#fed7ec"
android:centerY="0.75"
android:endColor="#fed7ec"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
其中的属性还要进一步研究具体作用,据文档翻译有设置角度,渐变的。
转载,仅供参考。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)