Skip to content

Commit

Permalink
Support text style
Browse files Browse the repository at this point in the history
  • Loading branch information
esafirm committed Feb 11, 2018
1 parent 305dd0e commit 7ce9494
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class FancyButton extends LinearLayout {

private Typeface mTextTypeFace = null;
private Typeface mIconTypeFace = null;
private int textStyle;

/**
* Tags to identify icon position
Expand Down Expand Up @@ -199,7 +200,7 @@ private TextView setupTextView() {
textView.setTextSize(Utils.pxToSp(getContext(), mDefaultTextSize));
textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
if (!isInEditMode() && !mUseSystemFont) {
textView.setTypeface(mTextTypeFace); //we can pass null in first arg
textView.setTypeface(mTextTypeFace, textStyle); //we can pass null in first arg
}
return textView;
}
Expand Down Expand Up @@ -335,6 +336,8 @@ private void initAttributesArray(TypedArray attrsArray) {

mIconPosition = attrsArray.getInt(R.styleable.FancyButtonsAttrs_fb_iconPosition, mIconPosition);

textStyle = attrsArray.getInt(R.styleable.FancyButtonsAttrs_android_textStyle, Typeface.NORMAL);

String fontIcon = attrsArray.getString(R.styleable.FancyButtonsAttrs_fb_fontIconResource);

String iconFontFamily = attrsArray.getString(R.styleable.FancyButtonsAttrs_fb_iconFont);
Expand Down Expand Up @@ -502,11 +505,11 @@ private void initializeButtonContainer() {
// https://github.com/medyo/Fancybuttons/issues/100
//this.setClickable(true);
//this.setFocusable(true);

if(mIconResource==null && mFontIcon==null && getPaddingLeft()==0 && getPaddingRight()==0 && getPaddingTop()==0 && getPaddingBottom()==0){
//fix for all version of androids and screens
this.setPadding(20, 0, 20, 0);
}
}
}

/**
Expand Down Expand Up @@ -801,8 +804,7 @@ public void setCustomTextFont(String fontName) {
if (mTextView == null)
initializeFancyButton();
else
mTextView.setTypeface(mTextTypeFace);

mTextView.setTypeface(mTextTypeFace, textStyle);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion fancybuttons_library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<attr name="android:text" />
<attr name="android:textSize" />
<attr name="android:textAllCaps" />
<attr name="android:textStyle" />

<attr name="fb_defaultColor" format="color" />
<attr name="fb_text" format="string" />
Expand Down Expand Up @@ -61,7 +62,7 @@
<attr name="fb_radiusTopRight" format="dimension"/>
<attr name="fb_radiusBottomLeft" format="dimension"/>
<attr name="fb_radiusBottomRight" format="dimension"/>

<attr name="fb_borderColor" format="color" />
<attr name="fb_borderWidth" format="dimension" />
<attr name="fb_focusColor" format="color" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package mehdi.sakout.fancybuttons.samples;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;


public class XmlButtons extends AppCompatActivity {
Expand All @@ -13,12 +14,20 @@ public class XmlButtons extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xml_buttons);

findViewById(R.id.btComments).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(view.getContext(), "Button clicked", Toast.LENGTH_SHORT)
.show();
}
});
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.xml_buttons, menu);
return true;
Expand Down
4 changes: 3 additions & 1 deletion samples/src/main/res/layout/activity_xml_buttons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
android:minLines="1"
android:padding="0dp"
android:text="comments"
android:textStyle="bold"
fancy:fb_borderColor="#FF4D3121"
fancy:fb_borderWidth="1dp"
fancy:fb_defaultColor="#731010"
Expand All @@ -46,6 +47,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:padding="10dp"
android:textStyle="italic"
fancy:fb_borderColor="#FFFFFF"
fancy:fb_borderWidth="1dp"
fancy:fb_defaultColor="#3b5998"
Expand Down Expand Up @@ -590,4 +592,4 @@

</LinearLayout>

</ScrollView>
</ScrollView>

0 comments on commit 7ce9494

Please sign in to comment.