Skip to content

Commit

Permalink
Set typeface from xml
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelgon47 committed Mar 4, 2017
1 parent 99276c2 commit f0ce3d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ public class WheelPicker extends View implements IDebug, IWheelPicker, Runnable
*/
private boolean isForceFinishScroll;

/**
* Font typeface path from assets
*/
private String fontPath;

private boolean isDebug;

public WheelPicker(Context context) {
Expand Down Expand Up @@ -310,6 +315,7 @@ public WheelPicker(Context context, AttributeSet attrs) {
hasAtmospheric = a.getBoolean(R.styleable.WheelPicker_wheel_atmospheric, false);
isCurved = a.getBoolean(R.styleable.WheelPicker_wheel_curved, false);
mItemAlign = a.getInt(R.styleable.WheelPicker_wheel_item_align, ALIGN_CENTER);
fontPath = a.getString(R.styleable.WheelPicker_wheel_font_path);
a.recycle();

// 可见数据项改变后更新与之相关的参数
Expand All @@ -319,6 +325,11 @@ public WheelPicker(Context context, AttributeSet attrs) {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.LINEAR_TEXT_FLAG);
mPaint.setTextSize(mItemTextSize);

if (fontPath != null) {
Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontPath);
setTypeface(typeface);
}

// 更新文本对齐方式
// Update alignment of text
updateItemTextAlign();
Expand Down
1 change: 1 addition & 0 deletions WheelPicker/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<enum name="left" value="1" />
<enum name="right" value="2" />
</attr>
<attr name="wheel_font_path" format="string" />
</declare-styleable>
</resources>

0 comments on commit f0ce3d2

Please sign in to comment.