Skip to content

Commit 9849d83

Browse files
committed
update to 1.6.4 增加selector属性使用的时候默认颜色设置
1 parent bc4fddb commit 9849d83

7 files changed

Lines changed: 127 additions & 44 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies {
3737
testImplementation 'junit:junit:4.12'
3838
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3939
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
40-
implementation 'com.noober.background:core:1.6.2'
40+
implementation 'com.noober.background:core:1.6.4'
4141
// implementation project(':library')
4242
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4343
}

app/src/main/java/com/noober/backgroudlibrary/MainActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
2929
// AnimationDrawable animationDrawable = (AnimationDrawable) vAnim.getBackground();
3030
// animationDrawable.start();
3131

32+
33+
// findViewById(R.id.tv111).setSelected(true);
34+
35+
// findViewById(R.id.select_view).setSelected(true);
36+
3237
Drawable drawable = new DrawableCreator.Builder().setCornersRadius(30)
3338
.setSolidColor(Color.parseColor("#FFFFFF"))
3439
.setStrokeColor(Color.parseColor("#FFFFFF"))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:drawable="@android:color/black" android:state_pressed="true" />
4+
<item android:drawable="@android:color/holo_red_dark" android:state_selected="true" />
5+
<item android:drawable="@android:color/darker_gray" />
6+
</selector>

app/src/main/res/layout/activity_main.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,47 @@
1313
tools:context=".MainActivity"
1414
tools:ignore="MissingPrefix">
1515

16+
17+
<TextView
18+
android:id="@+id/tv111"
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:text="今日持仓"
22+
android:textSize="12sp"
23+
android:paddingLeft="6dp"
24+
android:paddingRight="6dp"
25+
android:paddingTop="2dp"
26+
android:paddingBottom="2dp"
27+
android:background="@drawable/test_sel3" />
28+
29+
30+
<com.noober.background.view.BLFrameLayout
31+
android:id="@+id/select_view"
32+
android:layout_width="match_parent"
33+
android:layout_height="30dp"
34+
app:bl_corners_radius="15dp"
35+
app:bl_solid_color="@android:color/darker_gray"
36+
app:bl_selected_solid_color="@android:color/holo_red_dark"
37+
app:bl_pressed_solid_color="@android:color/black">
38+
39+
</com.noober.background.view.BLFrameLayout>
40+
41+
<com.noober.background.view.BLRadioButton
42+
android:layout_width="wrap_content"
43+
android:layout_height="wrap_content"
44+
android:text="今日持仓"
45+
android:textSize="12sp"
46+
android:paddingLeft="6dp"
47+
android:paddingRight="6dp"
48+
android:paddingTop="2dp"
49+
android:paddingBottom="2dp"
50+
app:bl_checked_solid_color="@color/colorPrimaryDark"
51+
app:bl_unCheckable_solid_color="#F4F4F4"
52+
app:bl_checked_textColor="@android:color/white"
53+
app:bl_unChecked_textColor="@color/colorPrimaryDark"
54+
app:bl_corners_radius="10dp" />
55+
56+
1657
<com.noober.background.view.BLButton
1758
android:id="@+id/btn_login"
1859
style="?android:attr/borderlessButtonStyle"

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ext {
3636
userOrg = 'noober'
3737
groupId = 'com.noober.background'
3838
uploadName = 'LibraryForBackground'
39-
publishVersion = '1.6.3'
39+
publishVersion = '1.6.4'
4040
desc = "A framework for directly generating shape through Tags, no need to write shape.xml again(通过标签直接生成shape,无需再写shape.xml)"
4141
website = 'https://github.com/JavaNoober/BackgroundLibrary'
4242
// gradlew clean build bintrayUpload -PbintrayUser=xiaoqiandroid -PbintrayKey=xxxxxxxxxxxxxxxx -PdryRun=false

library/src/main/java/com/noober/background/drawable/GradientDrawableCreator.java

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,57 +116,73 @@ public GradientDrawable create() throws XmlPullParserException {
116116
int start = 0;
117117
ArrayList<Integer> stateList = new ArrayList<>();
118118
ArrayList<Integer> colorList = new ArrayList<>();
119-
if (typedArray.hasValue(R.styleable.background_bl_pressed_solid_color) &&
120-
typedArray.hasValue(R.styleable.background_bl_unPressed_solid_color)) {
119+
if (typedArray.hasValue(R.styleable.background_bl_pressed_solid_color)) {
121120
stateList.add(android.R.attr.state_pressed);
122-
stateList.add(-android.R.attr.state_pressed);
123121
colorList.add(typedArray.getColor(R.styleable.background_bl_pressed_solid_color, 0));
122+
}
123+
if (typedArray.hasValue(R.styleable.background_bl_unPressed_solid_color)) {
124+
stateList.add(-android.R.attr.state_pressed);
124125
colorList.add(typedArray.getColor(R.styleable.background_bl_unPressed_solid_color, 0));
125126
}
126-
if (typedArray.hasValue(R.styleable.background_bl_checkable_solid_color) &&
127-
typedArray.hasValue(R.styleable.background_bl_unCheckable_solid_color)) {
127+
if (typedArray.hasValue(R.styleable.background_bl_checkable_solid_color)) {
128128
stateList.add(android.R.attr.state_checkable);
129-
stateList.add(-android.R.attr.state_checkable);
130129
colorList.add(typedArray.getColor(R.styleable.background_bl_checkable_solid_color, 0));
130+
}
131+
if (typedArray.hasValue(R.styleable.background_bl_unCheckable_solid_color)) {
132+
stateList.add(-android.R.attr.state_checkable);
131133
colorList.add(typedArray.getColor(R.styleable.background_bl_unCheckable_solid_color, 0));
132134
}
133-
if (typedArray.hasValue(R.styleable.background_bl_checked_solid_color) &&
134-
typedArray.hasValue(R.styleable.background_bl_unChecked_solid_color)) {
135+
if (typedArray.hasValue(R.styleable.background_bl_checked_solid_color)) {
135136
stateList.add(android.R.attr.state_checked);
136-
stateList.add(-android.R.attr.state_checked);
137137
colorList.add(typedArray.getColor(R.styleable.background_bl_checked_solid_color, 0));
138+
}
139+
if (typedArray.hasValue(R.styleable.background_bl_unChecked_solid_color)) {
140+
stateList.add(-android.R.attr.state_checked);
138141
colorList.add(typedArray.getColor(R.styleable.background_bl_unChecked_solid_color, 0));
139142
}
140-
if (typedArray.hasValue(R.styleable.background_bl_enabled_solid_color) &&
141-
typedArray.hasValue(R.styleable.background_bl_unEnabled_solid_color)) {
143+
if (typedArray.hasValue(R.styleable.background_bl_enabled_solid_color)) {
142144
stateList.add(android.R.attr.state_enabled);
143-
stateList.add(-android.R.attr.state_enabled);
144145
colorList.add(typedArray.getColor(R.styleable.background_bl_enabled_solid_color, 0));
146+
}
147+
if (typedArray.hasValue(R.styleable.background_bl_unEnabled_solid_color)) {
148+
stateList.add(-android.R.attr.state_enabled);
145149
colorList.add(typedArray.getColor(R.styleable.background_bl_unEnabled_solid_color, 0));
146150
}
147-
if (typedArray.hasValue(R.styleable.background_bl_selected_solid_color) &&
148-
typedArray.hasValue(R.styleable.background_bl_unSelected_solid_color)) {
151+
if (typedArray.hasValue(R.styleable.background_bl_selected_solid_color)) {
149152
stateList.add(android.R.attr.state_selected);
150-
stateList.add(-android.R.attr.state_selected);
151153
colorList.add(typedArray.getColor(R.styleable.background_bl_selected_solid_color, 0));
154+
}
155+
if (typedArray.hasValue(R.styleable.background_bl_unSelected_solid_color)) {
156+
stateList.add(-android.R.attr.state_selected);
152157
colorList.add(typedArray.getColor(R.styleable.background_bl_unSelected_solid_color, 0));
153158
}
154-
if (typedArray.hasValue(R.styleable.background_bl_focused_solid_color) &&
155-
typedArray.hasValue(R.styleable.background_bl_unFocused_solid_color)) {
159+
if (typedArray.hasValue(R.styleable.background_bl_focused_solid_color)) {
156160
stateList.add(android.R.attr.state_focused);
157-
stateList.add(-android.R.attr.state_focused);
158161
colorList.add(typedArray.getColor(R.styleable.background_bl_focused_solid_color, 0));
162+
}
163+
if (typedArray.hasValue(R.styleable.background_bl_unFocused_solid_color)) {
164+
stateList.add(-android.R.attr.state_focused);
159165
colorList.add(typedArray.getColor(R.styleable.background_bl_unFocused_solid_color, 0));
160166
}
161167

162168
if (stateList.size() > 0) {
163-
int[][] state = new int[stateList.size()][];
164-
int[] color = new int[stateList.size()];
169+
int size = stateList.size();
170+
if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
171+
size ++;
172+
}
173+
int[][] state = new int[size][];
174+
int[] color = new int[size];
165175
for (int iState : stateList) {
166176
state[start] = new int[]{iState};
167177
color[start] = colorList.get(start);
168178
start++;
169179
}
180+
181+
if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
182+
state[start] = new int[]{};
183+
color[start] = solidColor;
184+
}
185+
170186
ColorStateList colorStateList = new ColorStateList(state, color);
171187
drawable.setColor(colorStateList);
172188
} else if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {

libraryx/src/main/java/com/noober/background/drawable/GradientDrawableCreator.java

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class GradientDrawableCreator implements ICreateDrawable {
2525
}
2626

2727
@Override
28-
public Drawable create() throws XmlPullParserException {
28+
public GradientDrawable create() throws XmlPullParserException {
2929
GradientDrawable drawable = new GradientDrawable();
3030
float[] cornerRadius = new float[8];
3131
float sizeWidth = 0;
@@ -116,57 +116,73 @@ public Drawable create() throws XmlPullParserException {
116116
int start = 0;
117117
ArrayList<Integer> stateList = new ArrayList<>();
118118
ArrayList<Integer> colorList = new ArrayList<>();
119-
if (typedArray.hasValue(R.styleable.background_bl_pressed_solid_color) &&
120-
typedArray.hasValue(R.styleable.background_bl_unPressed_solid_color)) {
119+
if (typedArray.hasValue(R.styleable.background_bl_pressed_solid_color)) {
121120
stateList.add(android.R.attr.state_pressed);
122-
stateList.add(-android.R.attr.state_pressed);
123121
colorList.add(typedArray.getColor(R.styleable.background_bl_pressed_solid_color, 0));
122+
}
123+
if (typedArray.hasValue(R.styleable.background_bl_unPressed_solid_color)) {
124+
stateList.add(-android.R.attr.state_pressed);
124125
colorList.add(typedArray.getColor(R.styleable.background_bl_unPressed_solid_color, 0));
125126
}
126-
if (typedArray.hasValue(R.styleable.background_bl_checkable_solid_color) &&
127-
typedArray.hasValue(R.styleable.background_bl_unCheckable_solid_color)) {
127+
if (typedArray.hasValue(R.styleable.background_bl_checkable_solid_color)) {
128128
stateList.add(android.R.attr.state_checkable);
129-
stateList.add(-android.R.attr.state_checkable);
130129
colorList.add(typedArray.getColor(R.styleable.background_bl_checkable_solid_color, 0));
130+
}
131+
if (typedArray.hasValue(R.styleable.background_bl_unCheckable_solid_color)) {
132+
stateList.add(-android.R.attr.state_checkable);
131133
colorList.add(typedArray.getColor(R.styleable.background_bl_unCheckable_solid_color, 0));
132134
}
133-
if (typedArray.hasValue(R.styleable.background_bl_checked_solid_color) &&
134-
typedArray.hasValue(R.styleable.background_bl_unChecked_solid_color)) {
135+
if (typedArray.hasValue(R.styleable.background_bl_checked_solid_color)) {
135136
stateList.add(android.R.attr.state_checked);
136-
stateList.add(-android.R.attr.state_checked);
137137
colorList.add(typedArray.getColor(R.styleable.background_bl_checked_solid_color, 0));
138+
}
139+
if (typedArray.hasValue(R.styleable.background_bl_unChecked_solid_color)) {
140+
stateList.add(-android.R.attr.state_checked);
138141
colorList.add(typedArray.getColor(R.styleable.background_bl_unChecked_solid_color, 0));
139142
}
140-
if (typedArray.hasValue(R.styleable.background_bl_enabled_solid_color) &&
141-
typedArray.hasValue(R.styleable.background_bl_unEnabled_solid_color)) {
143+
if (typedArray.hasValue(R.styleable.background_bl_enabled_solid_color)) {
142144
stateList.add(android.R.attr.state_enabled);
143-
stateList.add(-android.R.attr.state_enabled);
144145
colorList.add(typedArray.getColor(R.styleable.background_bl_enabled_solid_color, 0));
146+
}
147+
if (typedArray.hasValue(R.styleable.background_bl_unEnabled_solid_color)) {
148+
stateList.add(-android.R.attr.state_enabled);
145149
colorList.add(typedArray.getColor(R.styleable.background_bl_unEnabled_solid_color, 0));
146150
}
147-
if (typedArray.hasValue(R.styleable.background_bl_selected_solid_color) &&
148-
typedArray.hasValue(R.styleable.background_bl_unSelected_solid_color)) {
151+
if (typedArray.hasValue(R.styleable.background_bl_selected_solid_color)) {
149152
stateList.add(android.R.attr.state_selected);
150-
stateList.add(-android.R.attr.state_selected);
151153
colorList.add(typedArray.getColor(R.styleable.background_bl_selected_solid_color, 0));
154+
}
155+
if (typedArray.hasValue(R.styleable.background_bl_unSelected_solid_color)) {
156+
stateList.add(-android.R.attr.state_selected);
152157
colorList.add(typedArray.getColor(R.styleable.background_bl_unSelected_solid_color, 0));
153158
}
154-
if (typedArray.hasValue(R.styleable.background_bl_focused_solid_color) &&
155-
typedArray.hasValue(R.styleable.background_bl_unFocused_solid_color)) {
159+
if (typedArray.hasValue(R.styleable.background_bl_focused_solid_color)) {
156160
stateList.add(android.R.attr.state_focused);
157-
stateList.add(-android.R.attr.state_focused);
158161
colorList.add(typedArray.getColor(R.styleable.background_bl_focused_solid_color, 0));
162+
}
163+
if (typedArray.hasValue(R.styleable.background_bl_unFocused_solid_color)) {
164+
stateList.add(-android.R.attr.state_focused);
159165
colorList.add(typedArray.getColor(R.styleable.background_bl_unFocused_solid_color, 0));
160166
}
161167

162168
if (stateList.size() > 0) {
163-
int[][] state = new int[stateList.size()][];
164-
int[] color = new int[stateList.size()];
169+
int size = stateList.size();
170+
if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
171+
size ++;
172+
}
173+
int[][] state = new int[size][];
174+
int[] color = new int[size];
165175
for (int iState : stateList) {
166176
state[start] = new int[]{iState};
167177
color[start] = colorList.get(start);
168178
start++;
169179
}
180+
181+
if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
182+
state[start] = new int[]{};
183+
color[start] = solidColor;
184+
}
185+
170186
ColorStateList colorStateList = new ColorStateList(state, color);
171187
drawable.setColor(colorStateList);
172188
} else if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
@@ -325,7 +341,6 @@ public Drawable create() throws XmlPullParserException {
325341
e.printStackTrace();
326342
}
327343
}
328-
329344
}
330345
return drawable;
331346
}

0 commit comments

Comments
 (0)