欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

自定义标题

程序员文章站 2022-07-13 23:17:22
...

public class MyView extends LinearLayout {

@BindView(R.id.back)
ImageView back;
@BindView(R.id.btn_fb)
Button btnFb;
@BindView(R.id.rel)
RelativeLayout rel;

public MyView(Context context, AttributeSet attrs) {
    super(context, attrs);
    View view = LayoutInflater.from(context).inflate(R.layout.myviwe, this, true);
    ButterKnife.bind(this, view);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyView);
    int color = typedArray.getColor(R.styleable.MyView_bgcolor, Color.RED);
    rel.setBackgroundColor(color);

}

@OnClick({R.id.back, R.id.btn_fb})
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.back:
            System.exit(0);
            break;
        case R.id.btn_fb:
            backs.bak();
            break;
    }
}
public interface Backs{
    void bak();
}
private Backs backs;
public void getBacks(Backs backs){
    this.backs = backs;
}

}