public class MyView extends RelativeLayout {
private Button rightBtn,LeftBtn;
private TextView tvTitle;
private String TitleText;
private float TitleSize;
private int TitleColor;
private String LeftText;
private Drawable leftBackground;
private int LeftColor;
private String rightText;
private Drawable rightBackground;
private int rightColor;
private LayoutParams leftParams,rightParams,TitleParmas;
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.TopBar);
LeftText = ta.getString(R.styleable.TopBar_LeftTitle);
leftBackground = ta.getDrawable(R.styleable.TopBar_LeftTitleBackground);
LeftColor = ta.getColor(R.styleable.TopBar_LeftTitleTextColor,0);
rightText = ta.getString(R.styleable.TopBar_RightTitle);
rightBackground = ta.getDrawable(R.styleable.TopBar_RightTitleBackground);
rightColor = ta.getColor(R.styleable.TopBar_RightTitleTextColor,0);
TitleText = ta.getString(R.styleable.TopBar_Title);
TitleSize = ta.getDimension(R.styleable.TopBar_TitleTextSize,0);
TitleColor = ta.getColor(R.styleable.TopBar_TitleTextColor,0);
ta.recycle();
LeftBtn = new Button(context);
rightBtn = new Button(context);
tvTitle = new TextView(context);
LeftBtn.setText(LeftText);
LeftBtn.setBackground(leftBackground);
LeftBtn.setTextColor(LeftColor);
rightBtn.setText(rightText);
rightBtn.setBackground(rightBackground);
rightBtn.setTextColor(rightColor);
tvTitle.setText(TitleText);
tvTitle.setTextSize(TitleSize);
tvTitle.setTextColor(TitleColor);
tvTitle.setGravity(Gravity.CENTER);
setBackgroundColor(0xFFF59563);
leftParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
leftParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT,TRUE);
addView(LeftBtn,leftParams);
rightParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
rightParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,TRUE);
addView(rightBtn,rightParams);
TitleParmas = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
TitleParmas.addRule(RelativeLayout.CENTER_IN_PARENT,TRUE);
addView(tvTitle,TitleParmas);
}

