Skip to content

Commit

Permalink
Merge pull request #14 from sgultekin/feature/text-alignment
Browse files Browse the repository at this point in the history
Implemented ability to set text gravity
  • Loading branch information
medyo committed Apr 11, 2015
2 parents 26187af + 11c3290 commit e1c0325
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions fancybuttons_library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@
<enum name="bottom" value="4" />
</attr>

<attr name="textGravity" format="enum">
<enum name="top" value="0x30" />
<enum name="bottom" value="0x50" />
<enum name="left" value="0x03" />
<enum name="right" value="0x05" />
<enum name="center_vertical" value="0x10" />
<enum name="fill_vertical" value="0x70" />
<enum name="center_horizontal" value="0x01" />
<enum name="fill_horizontal" value="0x07" />
<enum name="center" value="0x11" />
<enum name="fill" value="0x77" />
<enum name="clip_vertical" value="0x80" />
<enum name="clip_horizontal" value="0x08" />
<enum name="start" value="0x00800003" />
<enum name="end" value="0x00800005" />
</attr>

<attr name="iconPaddingLeft" format="dimension" />
<attr name="iconPaddingRight" format="dimension" />
<attr name="iconPaddingTop" format="dimension" />
Expand Down

0 comments on commit e1c0325

Please sign in to comment.