1
나는 다른 것들 사이에서 onDraw 재정의에 제공된 캔버스에 많은 텍스트를 직접 그려야하는 사용자 정의 android view 클래스가 있습니다.사용자 정의보기의 Android 속성
내가하고 싶은 것은 "android : attr/textAppearanceLarge"와 같은 것으로 설정할 수있는 속성을 가지고 있으며 더 이상 스타일을 지정하지 않고도 일반 텍스트 설정을 선택하는 것입니다. 내 사용자 정의보기의 attrs.xml이에서
, 나는 경우에,
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyView" >
...
<attr name="textAppearance" format="reference" />
...
</declare-styleable>
</resources>
다음 CustomView.java에
final int[] bogus = new int[] { android.R.attr.textColor, android.R.attr.textSize, android.R.attr.typeface, android.R.attr.textStyle, android.R.attr.fontFamily };
final int ap = styledAttributes.getResourceId(com.test.R.styleable.MyView_textAppearance, -1);
final TypedArray textAppearance = ap != -1 ? context.obtainStyledAttributes(ap, bogus) : null;
if (textAppearance != null) {
for (int i = 0; i < textAppearance.getIndexCount(); i++) {
int attr = textAppearance.getIndex(i);
switch (attr) {
case android.R.attr.textColor: textColor = textAppearance.getColor(attr, textColor); break;
case android.R.attr.textSize: textSize = textAppearance.getDimensionPixelSize(attr, textSize); break;
case android.R.attr.typeface: typefaceIndex = textAppearance.getInt(attr, typefaceIndex); break;
case android.R.attr.textStyle: textStyle = textAppearance.getInt(attr, textStyle); break;
case android.R.attr.fontFamily: fontFamily = textAppearance.getString(attr); break;
}
}
textAppearance.recycle();
}
내가 스위치 변수에 변화의 모든 종류를 시도했다가 상수 등등과 나는 끝내 결코 결코 아무것도 원격으로 유용합니다.
내가 뭘 잘못하고 있니? ,
com.test.R.styleable.MyView_textAppearance
자신이다
android.R.attr.textColor
을하고 다른 사람은 안드로이드의 위치 :