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"

? ?

? ?

? ?

? ?

? ?

? ?

? ?

? ?

? ?

? ?

? ?

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容