我正在开发一个适用于visual disabilities
. 如果设备有一个Android API
大于 14 我想增强Talkback
一下。
我ListView
填满了整个屏幕,每一行只有一个TextView
. 由于文本可能很长,我想marquee
在用户单击文本时使用单行来滚动文本。
我在没有的情况下对其进行了测试,并且Talkback
可以正常工作:
所以我决定用 Talkback active测试它。在这种情况下,我有两种问题:
1- 有些行根本不滚动。
2-有些行滚动,但我看不到比不滚动文本时显示的文本更多的文本:
我不知道为什么有些行滚动而有些不滚动,我对所有行都使用相同的代码。
要更改背景颜色并启动选取框,我将AccessibilityDelegate
在每一行添加一个。
这是每一行的布局:
<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>
这是我的适配器的一些代码:
@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();
}
}
有人知道我是否可以在 Talkback 中使用选框吗?
谢谢!