|
16 | 16 | import android.view.MotionEvent;
|
17 | 17 | import android.view.View;
|
18 | 18 | import android.widget.RelativeLayout;
|
| 19 | +import android.widget.TextView; |
19 | 20 |
|
20 | 21 | public class CheckBox extends CustomView {
|
21 | 22 |
|
@@ -70,20 +71,45 @@ public void run() {
|
70 | 71 | });
|
71 | 72 |
|
72 | 73 | checkView = new Check(getContext());
|
| 74 | + checkView.setId(View.generateViewId()); |
73 | 75 | RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
|
74 | 76 | getResources()), Utils.dpToPx(20, getResources()));
|
75 | 77 | params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
|
76 | 78 | checkView.setLayoutParams(params);
|
77 | 79 | addView(checkView);
|
78 | 80 |
|
| 81 | + // Adding text view to checkbox |
| 82 | + int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1); |
| 83 | + String text = null; |
| 84 | + |
| 85 | + if(textResource != -1) { |
| 86 | + text = getResources().getString(textResource); |
| 87 | + } else { |
| 88 | + text = attrs.getAttributeValue(ANDROIDXML, "text"); |
| 89 | + } |
| 90 | + |
| 91 | + if(text != null) { |
| 92 | + params.removeRule(RelativeLayout.CENTER_IN_PARENT); |
| 93 | + params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); |
| 94 | + TextView textView = new TextView(getContext()); |
| 95 | + RelativeLayout.LayoutParams textViewLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, |
| 96 | + LayoutParams.WRAP_CONTENT); |
| 97 | + textViewLayoutParams.addRule(RelativeLayout.RIGHT_OF, checkView.getId()); |
| 98 | + textViewLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); |
| 99 | + textViewLayoutParams.setMargins(10, 0, 0, 0); |
| 100 | + textView.setLayoutParams(textViewLayoutParams); |
| 101 | + textView.setText(text); |
| 102 | + |
| 103 | + addView(textView); |
| 104 | + } |
79 | 105 | }
|
80 |
| - |
| 106 | + |
81 | 107 | @Override
|
82 | 108 | public void invalidate() {
|
83 | 109 | checkView.invalidate();
|
84 | 110 | super.invalidate();
|
85 | 111 | }
|
86 |
| - |
| 112 | + |
87 | 113 |
|
88 | 114 | @Override
|
89 | 115 | public boolean onTouchEvent(MotionEvent event) {
|
@@ -137,7 +163,7 @@ private void changeBackgroundColor(int color) {
|
137 | 163 |
|
138 | 164 | /**
|
139 | 165 | * Make a dark color to press effect
|
140 |
| - * |
| 166 | + * |
141 | 167 | * @return
|
142 | 168 | */
|
143 | 169 | protected int makePressColor() {
|
|
0 commit comments