Мы используем библиотеку, которая содержит все стили, такие как межбуквенный интервал.Это вызвало некоторые проблемы в наших пользовательских представлениях, поскольку нам нужно было правильно использовать TextAppearance.
Я передаю TextAppearance через XML и пытался использовать его свойство на краске.Это работает с другими свойствами, такими как размер текста и FontTypeFace, но не работает из-за отсутствия функции textAppearanceSpan.getLetterSpacing()
.
XML передаются через объявленный стиль
attrs.xml
<declare-styleable name="MyCustomView">
<attr name="TextAppearance" />
</declare-styleable>
layout.xml
<MyCustomView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:TextAppearance="?attr/TextAppearanceBig" />
Затем я читаю эти элементы в
MyCustomView.java
Paint mPaint;
public MyCustomView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyCustomView, 0, 0);
int textAppearanceID = typedArray.getResourceId(R.styleable.MyCustomView_TextApperance);
TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(context, textApperanceID);
mPaint = new Paint();
mPaint.setTextSize(textAppearanceSpan.getTextSize());
mPaint.setTypeface(Typeface.create(textAppearanceSpan.getFamily(), Typeface.NORMAL);
}
@Override
protected synchronized void onDraw(Canvas canvas){
canvas.drawText("Hello World", 0, 0, mPaint);
}
Я хочу сделать mPaint.setLetterSpacing(textAppearanceSpan.getLetterSpacing())
, но функция textAppearanceSpan.getLetterSpacing()
не существует.