TextAndImgShowView.java
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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);
}
}