diff --git a/README.md b/README.md index 6acc61b..8e3e150 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,8 @@ Now, you have successfully created some TagViews. The following will show some m | tag_cross_area_padding | dimension | The padding of the cross area(default 10dp) | tag_support_letters_rlt | boolean | Whether to support 'letters show with RTL(eg: Android -> diordnA)' style(default false) | tag_background | reference | TagView background resource(default none background) +| tag_text_style | enum | TagView text style. (Like TextView text style) +| tag_text_font_family | string | TagView font family (ej. san-serif-medium) **You can set these attributes in layout file, or use setters(each attribute has get and set method) to set them.** diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index e36dccf..2b18c0f 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -29,12 +29,15 @@ import android.view.View; import android.view.ViewGroup; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import androidx.annotation.DrawableRes; +import androidx.annotation.IntDef; import androidx.customview.widget.ViewDragHelper; import static co.lujun.androidtagview.Utils.dp2px; @@ -156,6 +159,22 @@ public class TagContainerLayout extends ViewGroup { */ private int mTagTextColor = Color.parseColor("#FF666666"); + /** + * TagView text font family + */ + private String mTagTextFontFamily = null; + + + /** @hide */ + @IntDef(value = {Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC, Typeface.BOLD_ITALIC}) + @Retention(RetentionPolicy.SOURCE) + public @interface Style {} + + /** + * TagView text style + */ + private @Style int mTagTextStyle = Typeface.NORMAL; + /** * TagView typeface */ @@ -329,6 +348,8 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) { mTagBackgroundColor = attributes.getColor(R.styleable.AndroidTagView_tag_background_color, mTagBackgroundColor); mTagTextColor = attributes.getColor(R.styleable.AndroidTagView_tag_text_color, mTagTextColor); + mTagTextFontFamily = attributes.getString(R.styleable.AndroidTagView_tag_text_font_family); + mTagTextStyle = attributes.getInt(R.styleable.AndroidTagView_tag_text_style, mTagTextStyle); mTagTextDirection = attributes.getInt(R.styleable.AndroidTagView_tag_text_direction, mTagTextDirection); isTagViewClickable = attributes.getBoolean(R.styleable.AndroidTagView_tag_clickable, false); isTagViewSelectable = attributes.getBoolean(R.styleable.AndroidTagView_tag_selectable, false); @@ -561,6 +582,7 @@ private void onAddTag(String text, int position) { addView(tagView, position); } + private void initTagView(TagView tagView, int position) { int[] colors; if (mColorArrayList != null && mColorArrayList.size() > 0) { @@ -581,6 +603,15 @@ private void initTagView(TagView tagView, int position) { tagView.setTagMaxLength(mTagMaxLength); tagView.setTextDirection(mTagTextDirection); tagView.setTypeface(mTagTypeface); + + if (mTagTextFontFamily == null && mTagTextStyle != Typeface.NORMAL) { + tagView.setTypeface(Typeface.defaultFromStyle(mTagTextStyle)); + } else if (mTagTextFontFamily != null) { + tagView.setTypeface(Typeface.create(mTagTextFontFamily, mTagTextStyle)); + } else { + tagView.setTypeface(mTagTypeface); + } + tagView.setBorderWidth(mTagBorderWidth); tagView.setBorderRadius(mTagBorderRadius); tagView.setTextSize(mTagTextSize); @@ -1382,6 +1413,44 @@ public void setTagTextDirection(int textDirection) { this.mTagTextDirection = textDirection; } + + /** + * Get TagView FontFamily + * + * @return + */ + public String getTagTextFontFamily() { + return mTagTextFontFamily; + } + + /** + * Set TagView FontFamily. + * + * @param fontFamily + */ + public void setTagTextFontFamily(String fontFamily) { + this.mTagTextFontFamily = fontFamily; + } + + /** + * Get TagView text style. + * + * @return + */ + public @Style int getTagTextStyle() { + return mTagTextStyle; + } + + /** + * Set TagView text style. + * + * @param textStyle + */ + public void setTagTextStyle(@Style int textStyle) { + this.mTagTextStyle = textStyle; + } + + /** * Get TagView typeface. * diff --git a/androidtagview/src/main/res/values/attrs.xml b/androidtagview/src/main/res/values/attrs.xml index 098f9a9..b4c712c 100644 --- a/androidtagview/src/main/res/values/attrs.xml +++ b/androidtagview/src/main/res/values/attrs.xml @@ -24,6 +24,13 @@ + + + + + + + @@ -51,5 +58,6 @@ + \ No newline at end of file diff --git a/sample/src/main/res/layout/content_main.xml b/sample/src/main/res/layout/content_main.xml index bb89e68..5df45e7 100644 --- a/sample/src/main/res/layout/content_main.xml +++ b/sample/src/main/res/layout/content_main.xml @@ -39,6 +39,7 @@ app:tag_clickable="true" app:tag_enable_cross="true" app:tag_theme="pure_teal" + app:tag_text_style="italic" app:vertical_interval="10dp" />