快捷导航

自定义控件

帮忙看下错在哪


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

要把报错信息贴出来哦
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP