public class MainActivity5 extends Activity {
ProgressBar mProgressBar;
RelativeLayout root_RelativeLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main5);
root_RelativeLayout = (RelativeLayout) findViewById(R.id.root_RelativeLayout);
mProgressBar = new ProgressBar(this,null,android.R.attr.progressBarStyleHorizontal);
mProgressBar.setMax(100);
mProgressBar.setProgress(40);
mProgressBar.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_horizontal_1));
RelativeLayout.LayoutParams relLayoutParams = new RelativeLayout.LayoutParams(400,50);
relLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
relLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
int top = 100;
int left = 200;
relLayoutParams.setMargins(left, top, 0, 0);
root_RelativeLayout.addView(mProgressBar,relLayoutParams);
}
}
progressbar_horizontal_1.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- background -->
<item android:id="@android:id/background">
<shape>
<corners android:radius="15dp" />
<solid android:color="#D1D1D1" />
</shape>
</item>
<!-- progress -->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="15dp" />
<solid android:color="#FD8830" />
</shape>
</clip>
</item>
</layer-list>