From 11c329030a9fd6bd65b117c348790c2b4524fefd Mon Sep 17 00:00:00 2001 From: Samet Gultekin Date: Sat, 11 Apr 2015 00:55:37 +0300 Subject: [PATCH] Implemented ability to set text gravity --- .../mehdi/sakout/fancybuttons/FancyButton.java | 18 ++++++++++++++++-- .../src/main/res/values/attrs.xml | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java index 5745c70..ff7c595 100644 --- a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java +++ b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java @@ -32,6 +32,7 @@ public class FancyButton extends LinearLayout{ private int mDefaultTextColor = Color.WHITE; private int mTextPosition = 1; private int mDefaultTextSize = 15; + private int mDefaultTextGravity = 0x11; // Gravity.CENTER private String mText = null; // # Icon Attributes @@ -171,7 +172,7 @@ private TextView setupTextView(){ if (mText != null) { TextView textView = new TextView(mContext); textView.setText(mText); - textView.setGravity(Gravity.CENTER); + textView.setGravity(mDefaultTextGravity); textView.setTextColor(mDefaultTextColor); textView.setTextSize(mDefaultTextSize); @@ -269,10 +270,11 @@ private void initAttributsArray(TypedArray attrsArray){ mDefaultTextColor = attrsArray.getColor(R.styleable.FancyButtonsAttrs_textColor,mDefaultTextColor); mDefaultTextSize = (int) attrsArray.getDimension(R.styleable.FancyButtonsAttrs_textSize,mDefaultTextSize); + mDefaultTextGravity = attrsArray.getInt(R.styleable.FancyButtonsAttrs_textGravity, mDefaultTextGravity); mBorderColor = attrsArray.getColor(R.styleable.FancyButtonsAttrs_borderColor,mBorderColor); mBorderWidth = (int) attrsArray.getDimension(R.styleable.FancyButtonsAttrs_borderWidth,mBorderWidth); - + mRadius = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_radius,mRadius); mFontIconSize = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fontIconSize,mFontIconSize); @@ -446,6 +448,18 @@ public void setTextSize(int textSize){ mTextView.setTextSize(textSize); } + /** + * Set the gravity of Text + * @param gravity : Text Gravity + */ + + public void setTextGravity(int gravity) { + this.mDefaultTextGravity = gravity; + if (mTextView != null) { + mTextView.setGravity(gravity); + } + } + /** * Set Padding for mIconView and mFontIconSize * @param paddingLeft : Padding Left diff --git a/fancybuttons_library/src/main/res/values/attrs.xml b/fancybuttons_library/src/main/res/values/attrs.xml index d43c03b..b9ee786 100644 --- a/fancybuttons_library/src/main/res/values/attrs.xml +++ b/fancybuttons_library/src/main/res/values/attrs.xml @@ -27,6 +27,23 @@ + + + + + + + + + + + + + + + + +