幫忙看下錯在哪public?class?Topbar?extends?RelativeLayout{
????private?Button?rightButton;
????private?TextView?tvTitle;
????private?Button?leftButton;
????private?int?textColor;
????private?String?titleText;
????private?float?titleTextSize;
????private?Drawable?titleBackground;
????private?int?leftTextColor;
????private?String?leftText;
????private?float?leftTextSize;
????private?Drawable?leftBackground;
????private?int?rightTextColor;
????private?String?rightText;
????private?float?rightTextSize;
????private?Drawable?rightBackground;
????public?Topbar(Context?context,?AttributeSet?attrs)?{
????????super(context,?attrs);
????????TypedArray?ta?=?context.obtainStyledAttributes(attrs,?R
????????????????.styleable.Topbar);
????????leftBackground?=?ta.getDrawable(R.styleable.Topbar_leftTextBackgroung);
????????leftText?=?ta.getString(R.styleable.Topbar_leftText);
????????leftTextSize?=?ta.getFloat(R.styleable.Topbar_leftTextSize,?0);
????????leftTextColor?=?ta.getColor(R.styleable.Topbar_leftTextColor,?0);
????????rightBackground?=?ta.getDrawable(R.styleable.Topbar_rightTextBackgroung);
????????rightTextSize?=?ta.getFloat(R.styleable.Topbar_rightTextSize,?0);
????????rightText?=?ta.getString(R.styleable.Topbar_rightText);
????????rightTextColor?=?ta.getColor(R.styleable.Topbar_rightTextColor,?0);
????????titleTextSize?=?ta.getFloat(R.styleable.Topbar_titleTextSize,?0);
????????titleText?=?ta.getString(R.styleable.Topbar_title);
????????textColor?=?ta.getColor(R.styleable.Topbar_titleTextColor,?0);
????????titleBackground?=?ta.getDrawable(R.styleable.Topbar_titleBackground);
????????ta.recycle();
????????leftButton?=?new?Button(context);
????????rightButton?=?new?Button(context);
????????tvTitle?=?new?TextView(context);
????????leftButton.setText(leftText);
????????leftButton.setTextSize(leftTextSize);
????????leftButton.setBackground(leftBackground);
????????leftButton.setTextColor(leftTextColor);
????????rightButton.setText(rightText);
????????rightButton.setTextSize(rightTextSize);
????????rightButton.setBackground(rightBackground);
????????rightButton.setTextColor(rightTextColor);
????????tvTitle.setText(titleText);
????????tvTitle.setTextSize(titleTextSize);
????????tvTitle.setTextColor(textColor);
????????tvTitle.setBackground(titleBackground);
????????tvTitle.setGravity(Gravity.CENTER);
????????setBackgroundColor(0x008000);
????????LayoutParams?leftParams?=?new?LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
????????????????LayoutParams.WRAP_CONTENT);
????????leftParams.addRule(RelativeLayout.ALIGN_LEFT,?TRUE);
????????addView(leftButton,?leftParams);
????????LayoutParams?rightParams?=?new?LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
????????????????LayoutParams.WRAP_CONTENT);
????????rightParams.addRule(RelativeLayout.ALIGN_RIGHT,?TRUE);
????????addView(rightButton,?rightParams);
????????LayoutParams?titleParams?=?new?LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
????????????????LayoutParams.MATCH_PARENT);
????????titleParams.addRule(RelativeLayout.CENTER_IN_PARENT,?TRUE);
????????addView(tvTitle,?titleParams);
????}
}
添加回答
舉報
0/150
提交
取消