[英]Android: using marquee with TalkBack (Accessibility)
I'm developing an application adapted to people with visual disabilities
. 我正在开发适合
visual disabilities
的应用程序。 If the device has an Android API
greater than 14 I want to enhance Talkback
a bit. 如果设备的
Android API
大于14,我想稍微增强Talkback
。
I have a ListView
filling the whole screen where each row has just one TextView
. 我有一个
ListView
填充整个屏幕,其中每一行只有一个TextView
。 Since the text might be quite long, I wanted to use marquee
and single line to scroll the text when the user clicks in it. 由于文本可能会很长,因此我想在用户单击文本时使用
marquee
和单行滚动文本。
I tested it without Talkback
and it works: 我在没有
Talkback
情况下对其进行了测试,并且可以正常工作:
So I decided to test it with Talkback active . 因此,我决定在Talkback处于活动状态时对其进行测试。 In this case, I have two kind of problems:
在这种情况下,我有两种问题:
1- Some rows doesn't scroll at all. 1-有些行根本不滚动。
2- Some rows scroll, but I can't see more text than the one that is shown when the text isn't scrolled: 2-某些行会滚动,但我看不到比不滚动文本时显示的文本更多的文本:
I don't know why some rows scroll and some doesn't, I use the same code for all of them. 我不知道为什么有些行滚动而有些行不滚动,我对所有行都使用相同的代码。
To change the background color and start the marquee I'm adding an AccessibilityDelegate
to each row. 要更改背景颜色并启动选取框,我向每行添加一个
AccessibilityDelegate
。
This is the layout for each row: 这是每一行的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/rowTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:textSize="18dp" />
</LinearLayout>
And this is some of my adapter's code: 这是我的适配器的一些代码:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){ // If the View is not cached
// Inflates the Common View from XML file
convertView = this.inflater.inflate(R.layout.list_simple_row, parent, false);
}
TextView tv = (TextView) convertView.findViewById(R.id.rowTextView);
tv.setText( list.get(position) );
convertView.setContentDescription( list.get(position) );
addAccessibilityDelegate(tv, position); // Add delegate to the TextView to detect touches
tv.setSingleLine(true);
if(position == selected){
// The user touched this row: Change background color to green.
convertView.setBackgroundColor(Color.GREEN);
tv.setTextColor(Color.BLACK);
tv.setSelected(true);
}
else{
convertView.setBackgroundColor(Color.TRANSPARENT);
tv.setTextColor(Color.WHITE);
tv.setSelected(false);
}
return convertView;
}
protected void addAccessibilityDelegate( View v, final int position ){
v.setAccessibilityDelegate(new AccessibilityDelegate(){
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(host, event);
}
@Override
public void onInitializeAccessibilityNodeInfo(View host,
AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
}
@Override
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
if(event.getEventType() == AccessibilityEvent.TYPE_VIEW_HOVER_ENTER){
focusBackground(position);
}
}
});
}
public void focusBackground(int position){
if(selected != position){
selected = position;
notifyDataSetInvalidated();
}
}
Anybody knows if I can use marquee with Talkback? 有人知道我可以在“话语提示”中使用字幕吗?
Thank you! 谢谢!
Check out this bug on the Android bug tracker, it looks like Accessibility services interfere with the ellipsize property on TextViews. 在Android Bug Tracker上检查此bug ,看来辅助功能服务会干扰TextViews的ellipsize属性。 I was having similar issues with
android:ellipsize="start"
jumping to the start of the string until I disabled the LastPass Accessibility service. 在
android:ellipsize="start"
跳转到字符串的开头之前,我遇到了类似的问题,直到我禁用了LastPass Accessibility服务。 I verified that the Talkback service caused the same issue. 我确认对讲服务引起了同样的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.