Skip to content

Commit

Permalink
add attribute for TagView background
Browse files Browse the repository at this point in the history
  • Loading branch information
whilu committed Jun 1, 2017
1 parent 8fbc146 commit 073800f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.support.annotation.DrawableRes;
import android.support.v4.widget.ViewDragHelper;
import android.util.AttributeSet;
import android.view.Gravity;
Expand Down Expand Up @@ -237,6 +238,11 @@ public class TagContainerLayout extends ViewGroup {
*/
private float mCrossLineWidth = 1.0f;

/**
* TagView background resource
*/
private int mTagBackgroundResource;

public TagContainerLayout(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -305,6 +311,8 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) {
dp2px(context, mCrossLineWidth));
mTagSupportLettersRTL = attributes.getBoolean(R.styleable.AndroidTagView_tag_support_letters_rlt,
mTagSupportLettersRTL);
mTagBackgroundResource = attributes.getResourceId(R.styleable.AndroidTagView_tag_background,
mTagBackgroundResource);
attributes.recycle();

mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
Expand Down Expand Up @@ -550,6 +558,7 @@ private void initTagView(TagView tagView, int position) {
tagView.setCrossColor(mCrossColor);
tagView.setCrossLineWidth(mCrossLineWidth);
tagView.setTagSupportLettersRTL(mTagSupportLettersRTL);
tagView.setBackgroundResource(mTagBackgroundResource);
}

private void invalidateTags() {
Expand Down Expand Up @@ -1405,4 +1414,20 @@ public TagView getTagView(int position){
}
return (TagView) mChildViews.get(position);
}

/**
* Get TagView background resource
* @return
*/
public int getTagBackgroundResource() {
return mTagBackgroundResource;
}

/**
* Set TagView background resource
* @param tagBackgroundResource
*/
public void setTagBackgroundResource(@DrawableRes int tagBackgroundResource) {
this.mTagBackgroundResource = tagBackgroundResource;
}
}
1 change: 1 addition & 0 deletions androidtagview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
<attr name="tag_cross_line_width" format="dimension" />
<attr name="tag_cross_area_padding" format="dimension" />
<attr name="tag_support_letters_rlt" format="boolean" />
<attr name="tag_background" format="reference" />
</declare-styleable>
</resources>

0 comments on commit 073800f

Please sign in to comment.