After go through the several samples i figured out the problem.
Just replaced the line
TypedArray attr = context.obtainStyledAttributes(attrs,
R.styleable.Widget);
with this
TypedArray attr = context.getTheme().obtainStyledAttributes(attrs,
R.styleable.Widget,0,0)