val progressBar = ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal)
progressBar.minimumWidth = 800
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
progressBar.setProgress(30, true)
}else{
progressBar.progress = 30
}
progressBar.progressDrawable = resources.getDrawable(R.drawable.webview_progress);
val layoutParams: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 16)
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT)
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP)
// val top = 100
// val left = 200
// layoutParams.setMargins(left, top, 0, 0)
addView(progressBar, layoutParams)
webview_progress文件:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 背景 -->
<item android:id="@android:id/background">
<shape>
<solid android:color="@color/white" />
</shape>
</item>
<!-- 第二条进度条颜色 -->
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="@color/white" />
</shape>
</clip>
</item>
<!-- 进度条 -->
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#4169E1" />
</shape>
</clip>
</item>
</layer-list>