我创建了一个自定义TextView以使用我的字体图标。我的问题是我需要可访问性,但是我需要设置可访问性描述而忽略字体unicode。
class FontIcon(context: Context, attrs: AttributeSet?) :
AppCompatTextView(context, attrs) {
init {
val typedArray: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.FontIcon, 0, 0)
val fontOrdinal: Int = typedArray.getInt(R.styleable.FontIcon_iconStyle, 0)
FontHelper().setTextView(this, fontOrdinal)
super.setText(Html.fromHtml(this.text.toString()))
typedArray.recycle()
}
}
class FontHelper {
fun setTextView(text: TextView, fontOrdinal: Int): TextView {
val selectedFont = R.font.icon_line
val context = text.context.applicationContext
val typeface = ResourcesCompat.getFont(context, selectedFont)
text.typeface = typeface
text.importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO <- I added this to ignore for now the reading of the unicode
return text
}
}
在XML中是这样的: <br.com.mypackage.FontIcon
android:id="@+id/icon_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22dp"
android:text="\ue81a"
android:textColor="@color/heavy_grey"
app:srcCompat="@drawable/ic_lab_tube_experiment"/>
如何在此自定义TextView中设置可访问性描述,而忽略设置的文本? 最佳答案
您只需在contentDescription
上设置TextView
,它就会宣布内容而不是内容。
关于android - 使用自定义textview的字体图标的可访问性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/64127827/