Skip to content

Commit

Permalink
修复 setbackground on resume 后改变的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonLiu committed Aug 22, 2015
1 parent 4628d1d commit a7cdc19
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
11 changes: 11 additions & 0 deletions app/src/main/res/drawable-xhdpi/shape_tag_grey_with_border.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp" />

<stroke
android:width="1px"
android:color="#ddd" />

<solid android:color="#eee" />

</shape>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
app:textWordMargin="10dp"
app:textLineMargin="10dp"
app:textColor="#ff0000"
app:textBackground="@color/grey"
app:textBackground="@drawable/shape_tag_grey_with_border"
app:textPaddingLeft="10dp"
app:textPaddingRight="10dp"
app:textPaddingTop="10dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
Expand All @@ -29,7 +28,7 @@ public class MultipleTextViewGroup extends RelativeLayout {
private int textPaddingBottom;
private boolean overspread;
private int columnNum;
private Drawable textBackground;
private int textBackground;

private int layout_width;

Expand All @@ -46,7 +45,8 @@ public MultipleTextViewGroup(Context context, AttributeSet attrs) {
textSize = px2sp(context, textSize);
wordMargin = array.getDimensionPixelSize(R.styleable.MultipleTextViewGroup_textWordMargin, 0);
lineMargin = array.getDimensionPixelSize(R.styleable.MultipleTextViewGroup_textLineMargin, 0);
textBackground = array.getDrawable(R.styleable.MultipleTextViewGroup_textBackground);
textBackground = array.getResourceId(R.styleable.MultipleTextViewGroup_textBackground, -1);
//array.getc
textPaddingLeft = array.getDimensionPixelSize(R.styleable.MultipleTextViewGroup_textPaddingLeft, 0);
textPaddingRight = array.getDimensionPixelSize(R.styleable.MultipleTextViewGroup_textPaddingRight, 0);
textPaddingTop = array.getDimensionPixelSize(R.styleable.MultipleTextViewGroup_textPaddingTop, 0);
Expand Down Expand Up @@ -102,8 +102,8 @@ public void setTextViews(List<String> dataList) {
TextView tv = new TextView(context);
tv.setText(dataList.get(i));
tv.setTextSize(textSize);
if (textBackground != null)
tv.setBackgroundDrawable(textBackground);
if (textBackground != -1)
tv.setBackgroundResource(textBackground);

tv.setTextColor(textColor);
tv.setPadding(textPaddingLeft, textPaddingTop, textPaddingRight, textPaddingBottom);
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<attr name="textSize" format="dimension" />
<attr name="textWordMargin" format="dimension" />
<attr name="textLineMargin" format="dimension" />
<attr name="textBackground" format="integer" />
<attr name="textBackground" format="reference" />

<attr name="textPaddingLeft" format="dimension" />
<attr name="textPaddingRight" format="dimension" />
Expand Down

0 comments on commit a7cdc19

Please sign in to comment.