为了账号安全,请及时绑定邮箱和手机立即绑定

自定义控件

自定义控件

慕粉4089507 2017-06-17 16:37:09
帮忙看下错在哪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);     } }
查看完整描述

1 回答

?
ewang1986

TA贡献27条经验 获得超5个赞

要把报错信息贴出来哦

查看完整回答
反对 回复 2017-06-20
  • 1 回答
  • 0 关注
  • 828 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信