Skip to content

Commit

Permalink
add ability to change hint text size
Browse files Browse the repository at this point in the history
  • Loading branch information
aliab committed Nov 3, 2018
1 parent c075526 commit 82d5db2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
21 changes: 18 additions & 3 deletions library/src/main/java/ir/hamsaa/RtlMaterialSpinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public class RtlMaterialSpinner extends AppCompatSpinner implements ValueAnimato
private float arrowSize;
private boolean enableErrorLabel;
private boolean enableFloatingLabel;
private float hintTextSize;
private boolean isRtl;

private HintAdapter hintAdapter;
Expand Down Expand Up @@ -175,8 +176,10 @@ private void initAttributes(Context context, AttributeSet attrs)
arrowSize = array.getDimension(R.styleable.RtlMaterialSpinner_ms_arrowSize, dpToPx(DEFAULT_ARROW_WIDTH_DP));
enableErrorLabel = array.getBoolean(R.styleable.RtlMaterialSpinner_ms_enableErrorLabel, true);
enableFloatingLabel = array.getBoolean(R.styleable.RtlMaterialSpinner_ms_enableFloatingLabel, true);
hintTextSize = array.getFloat(R.styleable.RtlMaterialSpinner_ms_hintTextSize, getResources().getDimensionPixelSize(R.dimen.label_text_size));
isRtl = array.getBoolean(R.styleable.RtlMaterialSpinner_ms_isRtl, false);


String typefacePath = array.getString(R.styleable.RtlMaterialSpinner_ms_typeface);
if (typefacePath != null)
{
Expand Down Expand Up @@ -210,12 +213,10 @@ public void run()
private void initPaintObjects()
{

int labelTextSize = getResources().getDimensionPixelSize(R.dimen.label_text_size);

paint = new Paint(Paint.ANTI_ALIAS_FLAG);

textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextSize(labelTextSize);
textPaint.setTextSize(hintTextSize);
if (typeface != null)
{
textPaint.setTypeface(typeface);
Expand Down Expand Up @@ -479,6 +480,9 @@ protected void onDraw(Canvas canvas)
{
textPaint.setAlpha((int) ((0.8 * floatingLabelPercent + 0.2) * baseAlpha * floatingLabelPercent));
}

textPaint.setTextSize(dpToPx(hintTextSize));

String textToDraw = floatingLabelText != null ? floatingLabelText.toString() : hint.toString();
if (isRtl)
{
Expand Down Expand Up @@ -650,6 +654,17 @@ public void setHintColor(int hintColor)
invalidate();
}

/**
* Set hintTextSize in px
*
* @param hintTextSize hint text size in px
*/
public void setHintTextSizeInPixel(float hintTextSize)
{
textPaint.setTextSize(hintTextSize);
invalidate();
}

public int getErrorColor()
{
return errorColor;
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<attr name="ms_enableFloatingLabel" format="boolean"/>
<attr name="ms_enableErrorLabel" format="boolean"/>
<attr name="ms_isRtl" format="boolean"/>
<attr name="ms_hintTextSize" format="float"/>

</declare-styleable>
</resources>

0 comments on commit 82d5db2

Please sign in to comment.