package com.shunzhi.parent.views; import android.content.Context; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.shunzhi.parent.R; /** * Created by ToaHanDong on 2018/1/22. */ public class TextAndImgShowView extends LinearLayout { public TextAndImgShowView(Context context) { super(context); init(context); } public TextAndImgShowView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(context); } public TextAndImgShowView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); } ImageView image; TextView text; FrameLayout layout; int[] imgs = null; boolean isSelect = false; private void init(Context context) { View view = View.inflate(context, R.layout.text_and_img_show, this); image = view.findViewById(R.id.image); text = view.findViewById(R.id.text); layout = view.findViewById(R.id.layout); } public void setImgs(@DrawableRes int normalDrawable, @DrawableRes int selectDrawable) { imgs = new int[]{normalDrawable, selectDrawable}; } public void setSelect(boolean isSelect) { if (isSelect) { if (imgs != null && imgs.length > 1) image.setImageResource(imgs[1]); } else { if (imgs != null && imgs.length > 1) image.setImageResource(imgs[0]); } } public void setText(String content) { text.setText(content); } public void setTextColor(int color){ text.setTextColor(color); } }