The solution has customized bar control
with lot of functions to set various features of control like color,
percentage value.
The solution contains the source code
for bar control that can be readily integrated to an Android project.
package com.sample.Applicationbar; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Paint.FontMetrics; import android.util.AttributeSet; import android.util.Log; import android.view.View; public class BarClass extends View { private Paint paint; private long total,covered; public BarClass(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } public void onDraw(Canvas canvas) { String text="25"; paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.TRANSPARENT); canvas.drawPaint(paint); //setBackgroundResource(R.drawable.background); - To set image as background paint.setColor(Color.DKGRAY); Log.v("Raj","Width="+getWidth()); Log.v("Raj","Height="+getHeight()); //Rect r = new Rect(10,10,90,90); Rect r = new Rect(2,2,getWidth()-2,getHeight()-20); canvas.drawRect(r, paint); //canvas.drawRect(getPaddingLeft(), getPaddingTop(), getPaddingRight(),getPaddingBottom(), paint); Log.v("Raj","getPaddingLeft()="+getPaddingLeft()); Log.v("Raj","getPaddingRight()="+getPaddingRight()); Log.v("Raj","getPaddingTop()="+getPaddingTop()); Log.v("Raj","getPaddingBottom()="+getPaddingBottom()); paint.setTextSize(getHeight()*0.1f); float xpos = (getWidth()-2-paint.measureText(text))/2; int height=20-2; FontMetrics fm = paint.getFontMetrics(); float ypos = getHeight()-20 +2 + height/2-(fm.ascent + fm.descent) / 2; Log.v("Dinesh","paint.measureText(text)="+paint.measureText(text)); canvas.drawText(text,xpos,ypos,paint); } public void setpercent (long total,long covered){ this.total=total; this.covered=covered; } }
Thanks for your grateful informations, this blogs will be really help for Java tutorial .