[英]Accessibility using custom textview for Font Icons
I created a custom TextView to use my font icons.我创建了一个自定义 TextView 来使用我的字体图标。 My issue is that I need accessibility but I need set the accessibility description ignoring the font unicode.
我的问题是我需要可访问性,但我需要设置可访问性描述而忽略字体 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
}
}
in the XML is like this:在 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"/>
How can I set the accessibility description in this custom TextView ignoring the text that is set?如何在忽略设置的文本的情况下在此自定义 TextView 中设置辅助功能描述?
您只需在TextView
上设置contentDescription
,它就会宣布该内容而不是内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.