diff --git a/.idea/misc.xml b/.idea/misc.xml index fbb6828..5d19981 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/src/main/res/drawable-xxhdpi/selector_red.xml b/app/src/main/res/drawable-xxhdpi/selector_red.xml new file mode 100644 index 0000000..696be09 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/selector_red.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/common_textview_layout.xml b/app/src/main/res/layout/common_textview_layout.xml index 910dcb6..f1569cf 100644 --- a/app/src/main/res/layout/common_textview_layout.xml +++ b/app/src/main/res/layout/common_textview_layout.xml @@ -136,6 +136,38 @@ ctv:cRightTextString="" ctv:cUseRipple="true" /> + + + + + + + + diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml index 28aeb8e..0615aea 100644 --- a/app/src/main/res/layout/main.xml +++ b/app/src/main/res/layout/main.xml @@ -82,13 +82,13 @@ + stv:sLeftIconRes="@drawable/ic_hint_music" + stv:sLeftIconWidth="25dp" + stv:sLeftTextString="自定义图片大小" + stv:sRightTextString="20dp" /> + stv:sLeftIconRes="@drawable/ic_update_password" + stv:sLeftIconWidth="30dp" + stv:sLeftTextString="自定义图片大小" + stv:sRightTextString="30dp" /> + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 3ab3e9c..65c1f13 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,4 +3,6 @@ #3F51B5 #303F9F #FF4081 + #9e9e9e + #fd5353 diff --git a/library/build.gradle b/library/build.gradle index b94b4e9..8a7b830 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -12,8 +12,8 @@ android { defaultConfig { minSdkVersion 11 targetSdkVersion 24 - versionCode 110 - versionName "1.1.0" + versionCode 111 + versionName "1.1.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/library/src/main/java/com/allen/library/CommonTextView.java b/library/src/main/java/com/allen/library/CommonTextView.java index e60dc6b..b3773d3 100644 --- a/library/src/main/java/com/allen/library/CommonTextView.java +++ b/library/src/main/java/com/allen/library/CommonTextView.java @@ -171,6 +171,9 @@ public class CommonTextView extends RelativeLayout { private OnCommonTextViewClickListener onCommonTextViewClickListener; + private Drawable mBackground_drawable; + private boolean mIsCenterAlignLeft = false; + private int mCenterViewMarginLeft; public CommonTextView(Context context) { this(context, null); @@ -300,6 +303,11 @@ private void getAttr(AttributeSet attrs) { mCenterViewIsClickable = typedArray.getBoolean(R.styleable.CommonTextView_cCenterViewIsClickable, false); mRightViewIsClickable = typedArray.getBoolean(R.styleable.CommonTextView_cRightViewIsClickable, false); + mBackground_drawable = typedArray.getDrawable(R.styleable.CommonTextView_cBackgroundDrawableRes); + + mIsCenterAlignLeft = typedArray.getBoolean(R.styleable.CommonTextView_cIsCenterAlignLeft, false); + mCenterViewMarginLeft = typedArray.getDimensionPixelSize(R.styleable.CommonTextView_cCenterViewMarginLeft, dip2px(mContext, 200)); + typedArray.recycle(); } @@ -364,6 +372,9 @@ public void onClick(View v) { } } }); + if (mBackground_drawable != null) { + this.setBackgroundDrawable(mBackground_drawable); + } } /** @@ -558,17 +569,29 @@ private void initLeftBottomText() { private void initCenterText() { if (centerTextView == null) { if (centerTVParams == null) { - centerTVParams = getParams(centerTVParams); + if (mIsCenterAlignLeft) { + centerTVParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); + } else { + centerTVParams = getParams(centerTVParams); + } } centerTVParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); centerTVParams.addRule(RelativeLayout.CENTER_IN_PARENT, TRUE); - centerTVParams.setMargins(mCenterViewPaddingLeft, 0, mCenterViewPaddingRight, 0); - centerTextView = initText(centerTextView, centerTVParams, R.id.cCenterTextId, mCenterTextColor, mCenterTextSize); + if (mIsCenterAlignLeft) { + centerTextView = initText(centerTextView, centerTVParams, R.id.cCenterTextId, mCenterTextColor, mCenterTextSize); + centerTVParams.setMargins(mCenterViewMarginLeft, 0, mCenterViewPaddingRight, 0); + setTextViewGravity(centerTextView, Gravity_Left_Center); + } else { + centerTextView = initText(centerTextView, centerTVParams, R.id.cCenterTextId, mCenterTextColor, mCenterTextSize); + centerTVParams.setMargins(mCenterViewPaddingLeft, 0, mCenterViewPaddingRight, 0); + setTextViewGravity(centerTextView, mCenterTextViewGravity); + } + centerTextView.setText(mCenterTextString); centerTextView.setLineSpacing(mCenterTextViewLineSpacingExtra, 1.0f); - setTextViewGravity(centerTextView, mCenterTextViewGravity); + if (mCenterViewIsClickable) { centerTextView.setOnClickListener(new OnClickListener() { @Override diff --git a/library/src/main/java/com/allen/library/SuperTextView.java b/library/src/main/java/com/allen/library/SuperTextView.java index 0034a98..92f9a68 100644 --- a/library/src/main/java/com/allen/library/SuperTextView.java +++ b/library/src/main/java/com/allen/library/SuperTextView.java @@ -136,6 +136,8 @@ public class SuperTextView extends RelativeLayout { private boolean mLeftBottomViewIsClickable = false; private boolean mLeftBottomView2IsClickable = false; + private Drawable mBackground_drawable; + public SuperTextView(Context context) { super(context); } @@ -236,6 +238,8 @@ private void getAttr(AttributeSet attrs) { mLeftBottomViewIsClickable = typedArray.getBoolean(R.styleable.SuperTextView_sLeftBottomViewIsClickable, false); mLeftBottomView2IsClickable = typedArray.getBoolean(R.styleable.SuperTextView_sLeftBottomView2IsClickable, false); + mBackground_drawable = typedArray.getDrawable(R.styleable.SuperTextView_sBackgroundDrawableRes); + typedArray.recycle(); } @@ -337,6 +341,9 @@ public void onClick(View view) { if (useRipple) { this.setBackgroundResource(R.drawable.selector_white); } + if (mBackground_drawable != null) { + this.setBackgroundDrawable(mBackground_drawable); + } } diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index a32234f..9e140b2 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -101,6 +101,8 @@ + + @@ -221,6 +223,10 @@ + + + + \ No newline at end of file