Skip to content

Commit c97b677

Browse files
committed
update to 1.6.3
1 parent 3bee275 commit c97b677

5 files changed

Lines changed: 90 additions & 5 deletions

File tree

README-EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ A framework for directly generating shape through Tags, no need to write shape.x
77
Add this to your app's build.gradle:
88

99
implementation "com.android.support:appcompat-v7:$supportVersion"
10-
implementation 'com.noober.background:core:1.6.2'
10+
implementation 'com.noober.background:core:1.6.3'
1111

1212
if use androidx:
1313

1414
implementation "androidx.appcompat:appcompat:$supportVersion"
15-
implementation 'com.noober.background:core:1.6.2'
15+
implementation 'com.noober.background:core:1.6.3'
1616

1717

1818
## Example effect

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ A framework for directly generating shape through Tags, no need to write shape.x
1010
依赖方式:
1111

1212
implementation "com.android.support:appcompat-v7:$supportVersion"
13-
implementation 'com.noober.background:core:1.6.2'
13+
implementation 'com.noober.background:core:1.6.3'
1414

1515
如果项目使用了androidx:
1616

1717
implementation "androidx.appcompat:appcompat:$supportVersion"
18-
implementation 'com.noober.background:core:1.6.2'
18+
implementation 'com.noober.background:core:1.6.3'
1919

2020

2121
## 使用文档

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.2'
39+
publishVersion = '1.6.3'
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/DrawableCreator.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
import android.annotation.TargetApi;
44
import android.content.res.ColorStateList;
5+
import android.content.res.TypedArray;
56
import android.graphics.Rect;
67
import android.graphics.drawable.Drawable;
78
import android.graphics.drawable.GradientDrawable;
89
import android.graphics.drawable.RippleDrawable;
910
import android.graphics.drawable.StateListDrawable;
1011
import android.os.Build;
1112
import android.support.annotation.NonNull;
13+
import android.view.View;
14+
import android.widget.TextView;
15+
16+
import com.noober.background.R;
1217

1318
import java.lang.reflect.Field;
1419
import java.util.ArrayList;
@@ -41,6 +46,12 @@ public enum Gradient {
4146
}
4247
}
4348

49+
public enum DrawablePosition {
50+
51+
Left, Right, Top, Bottom
52+
53+
}
54+
4455
public static class Builder {
4556
private Shape shape = Shape.Rectangle;
4657
private Integer solidColor;
@@ -899,6 +910,38 @@ StateListDrawable getStateListDrawable(StateListDrawable stateListDrawable) {
899910
}
900911
return stateListDrawable;
901912
}
913+
}
914+
915+
// 设置drawable的位置
916+
public static void setDrawable(Drawable drawable, View view, DrawablePosition drawablePosition) {
917+
918+
if (view instanceof TextView) {
919+
if (drawablePosition == DrawablePosition.Left) {
920+
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
921+
((TextView) view).setCompoundDrawables(drawable, null, null, null);
922+
} else if (drawablePosition == DrawablePosition.Top) {
923+
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
924+
((TextView) view).setCompoundDrawables(null, drawable, null, null);
925+
} else if (drawablePosition == DrawablePosition.Right) {
926+
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
927+
((TextView) view).setCompoundDrawables(null, null, drawable, null);
928+
} else if (drawablePosition == DrawablePosition.Bottom) {
929+
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
930+
((TextView) view).setCompoundDrawables(null, null, null, drawable);
931+
} else {
932+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
933+
view.setBackground(drawable);
934+
} else {
935+
view.setBackgroundDrawable(drawable);
936+
}
937+
}
938+
} else {
939+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
940+
view.setBackground(drawable);
941+
} else {
942+
view.setBackgroundDrawable(drawable);
943+
}
944+
}
902945

903946
}
904947
}

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import android.graphics.drawable.RippleDrawable;
99
import android.graphics.drawable.StateListDrawable;
1010
import android.os.Build;
11+
import android.view.View;
12+
import android.widget.TextView;
1113

1214
import androidx.annotation.NonNull;
1315

@@ -42,6 +44,12 @@ public enum Gradient {
4244
}
4345
}
4446

47+
public enum DrawablePosition {
48+
49+
Left, Right, Top, Bottom
50+
51+
}
52+
4553
public static class Builder {
4654
private Shape shape = Shape.Rectangle;
4755
private Integer solidColor;
@@ -902,4 +910,38 @@ StateListDrawable getStateListDrawable(StateListDrawable stateListDrawable) {
902910
}
903911

904912
}
913+
914+
915+
// 设置drawable的位置
916+
public static void setDrawable(Drawable drawable, View view, DrawablePosition drawablePosition) {
917+
918+
if (view instanceof TextView) {
919+
if (drawablePosition == DrawablePosition.Left) {
920+
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
921+
((TextView) view).setCompoundDrawables(drawable, null, null, null);
922+
} else if (drawablePosition == DrawablePosition.Top) {
923+
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
924+
((TextView) view).setCompoundDrawables(null, drawable, null, null);
925+
} else if (drawablePosition == DrawablePosition.Right) {
926+
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
927+
((TextView) view).setCompoundDrawables(null, null, drawable, null);
928+
} else if (drawablePosition == DrawablePosition.Bottom) {
929+
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
930+
((TextView) view).setCompoundDrawables(null, null, null, drawable);
931+
} else {
932+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
933+
view.setBackground(drawable);
934+
} else {
935+
view.setBackgroundDrawable(drawable);
936+
}
937+
}
938+
} else {
939+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
940+
view.setBackground(drawable);
941+
} else {
942+
view.setBackgroundDrawable(drawable);
943+
}
944+
}
945+
946+
}
905947
}

0 commit comments

Comments
 (0)