InputBtnView

public class InputBtnView extends RelativeLayout {

private final TextView mTvLeft;

    private final TextView mTvRight;

    private final ImageView mIvRight;

    public InputBtnView(Context context, AttributeSet attrs) {

super(context, attrs);

        LayoutInflater.from(context).inflate(R.layout.btn_input, this, true).setBackgroundColor(Color.WHITE);

        mTvLeft = findViewById(R.id.btn_input_tv_left);

        mTvRight = findViewById(R.id.btn_input_tv_right);

        mIvRight = findViewById(R.id.btn_input_iv_right);

        View mLine = findViewById(R.id.btn_input_line);

        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.BtnInput);

        if (attributes !=null) {

String leftStr =attributes.getString(R.styleable.BtnInput_btn_tv_left_text);

            if (!TextUtils.isEmpty(leftStr)) {

mTvLeft.setText(leftStr);

            }

String rightStr =attributes.getString(R.styleable.BtnInput_btn_tv_right_text);

            if (!TextUtils.isEmpty(rightStr)) {

mTvRight.setText(rightStr);

            }

if (attributes.getBoolean(R.styleable.BtnInput_btn_iv_right_show, true)){

mIvRight.setImageResource(attributes.getResourceId(R.styleable.BtnInput_btn_iv_right_src,R.mipmap.into));

                mIvRight.setVisibility(View.VISIBLE);

            }else{

mIvRight.setVisibility(View.GONE);

            }

mTvLeft.setTextColor(attributes.getColor(R.styleable.BtnInput_btn_tv_left_color, ContextCompat.getColor(context,R.color.colorBtnTvLeft)));

            mTvRight.setTextColor(attributes.getColor(R.styleable.BtnInput_btn_tv_right_color, ContextCompat.getColor(context,R.color.colorBtnTvRight)));

            if (attributes.getBoolean(R.styleable.BtnInput_btn_line_show,true)){

mLine.setVisibility(View.VISIBLE);

            }else{

mLine.setVisibility(View.GONE);

            }

attributes.recycle();

        }

}

public void setTvLeftText(String content){

mTvLeft.setText(content);

    }

public void setTvRightText(String content){

mTvRight.setText(content);

    }

public void setTvLeftColor(int color){

mTvLeft.setTextColor(color);

    }

public void setTvRightColor(int color){

mTvRight.setTextColor(color);

    }

public void setIvRightShow(boolean show){

if (show){

mIvRight.setVisibility(View.VISIBLE);

        }else{

mIvRight.setVisibility(View.GONE);

        }

}

public void setIvRightBitmap(Bitmap bitmap){

mIvRight.setImageBitmap(bitmap);

    }

}


attrs:

   name="btn_tv_left_color" format="color"

name="btn_tv_right_color" format="color"

   "btn_tv_left_text" format="string"

"btn_tv_right_text" format="string"

name="btn_iv_right_src" format="reference|integer"

name="btn_iv_right_show" format="boolean"

   name="btn_line_show" format="boolean"

   

   

   

   

   

   

   

   

   

   

   

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容