I have four TextViews, and I'm trying to control the order that they get focus when a user navigates using TalkBack and touch gestures.
TextView android:text="foo" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="#+id/id_foo" android:nextFocusDown="#+id/id_baz"/>
TextView android:text="bar" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="#+id/id_bar" android:nextFocusDown="#+id/id_qux"/>
TextView android:text="baz" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="#id/id_baz" android:nextFocusDown="#id/id_bar"/>
TextView android:text="qux" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="#id/id_qux" android:nextFocusDown="#id/id_foo"/>
When a user turns on TalkBack, touches "foo", and then swipes down to navigate between the TextViews, I want the order to go foo->baz->bar->qux. But, the order I try to set up using nextFocusDown seems to have no effect, and instead focus order always just follows the positions of the TextViews on the screen. I've tried every possible combination of clickable, focusable, and focusableInTouchMode. I've tried calling setNextFocusDownId on the views in code. I've tried setting android:imeOptions="actionNext" on the TextViews. Nothing seems to work. What am I missing?
Try to use View.setAccessibilityTraversalAfter(int) and View.setAccessibilityTraversalBefore(int) to configure TalkBack navigation. Please note that TalkBack has only two directions:
forward (swipe to the right or down)
back (swipe to the left or up).
Example:
findView(R.id.bar).setAccessibilityTraversalBefore(R.id.quix);
NextFocusDown doesn't refer to TalkBack gestures. It refers to track-ball and keyboard arrow key navigation. TalkBack exploration gestures are limited to swiping down/right for next focus, and swiping up/left for previous focus. And of course, drag to explore.
Related
Android 9 has introduced accessibilityHeading tag, which can be used by talkback to announce the Headings.
https://developer.android.com/about/versions/pie/android-9.0#a11y
Look for Heading-based navigation
In my app I have multiple Textviews in my activity with some Headings
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:accessibilityHeading="true"
android:text="Accessibility Heading 1"
android:textColor="#000000"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="Message"
android:textColor="#000000" />
But when I run the app, headings are treated as normal textviews only and no special treatment is given by Talkback.
I can swipe left to navigate through all elements.
There is option to swipe up to change mode for talkback announcements. e.g Default, Links, Controls, Headings etc.
When chosen Headings, I expect talkback to announce only headings and to jump from one heading to another but it stays at the same place even after Swipe Left or Swipe Right gesture.
Set both accessibilityHeading and focusableInTouchMode to true. Then, after setting the navigation mode to Headers (you can do this via the up down gesture), swiping up or down navigates you though the headers. Swiping right and left will still allow you to navigate through single items.
I just tried, it work here as expected.
Talkback properly announces textviews as headings and in heading mode I can navigate to them as well.
Please ensure that you are using the latest version of Talkback.
This is quite an old question so may be you may have got the solution since then
I was having the same issue.
In my particular situation it was fixed when I set focusable and focusableInTouchMode to false in the parent view, and true in the TextView.
Try stacking two fragments with editTexts on top of each other using an Add Transaction. after that when you press the keyboard imeOption key next button the bottom fragment's edit text can gain focus. this is a security concern. user can type things into the bottom fragments edit text (blindly). I tried the following code:
android:filterTouchesWhenObscured="true"
but it has not helped at least on api 27.
my edit text itself looks like this, nothing special:
<EditText
android:id="#+id/et"
android:layout_width="195dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:imeOptions="actionNone"
android:layout_marginBottom="10dp"
android:hint="#string/enter_name"
android:filterTouchesWhenObscured="true"
android:inputType="textNoSuggestions"
android:textColorHint="#959595"
android:textSize="11sp" />
the issue is very similar to android tap jacking
i tried even doing this:
android:nextFocusDown="#+id/et_two" thinking it would bypass and go directly to the edittext i want. but instead the bottom edit text still gains focus.
the issue solution was surprising. recyclerview was stealing focus. see this SO incident:
adding android:descendantFocusability="blocksDescendants" to the recyclerview stopped the issue.
As you know time picker has three segments, two buttons on top and bottom of view and an editor in between.
By tap and holding editor, we can select its contents. The problem that I have is I want to select content of editor just by taping (not tap and hold). Is it possible?
Try something like this in layout file
<TimePicker
android:id="#+id/activity_main_timepicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dip"
android:layout_marginRight="16dip"
android:focusable="true"
android:focusableInTouchMode="true" />
Unlike most other controls, EditTexts are focusable while the system is in 'touch mode'.
The first click event focuses the control, while the second click event actually fires the
OnClickListener. If you disable touch-mode focus with the android:focusableInTouchMode View
attribute, the OnClickListener should fire as expected.
<EditText
android:id="#+id/textbox"
android:singleLine="true"
android:scrollbars="horizontal"
android:scrollHorizontally="true" />
((EditText)findViewById(R.id.display)).setKeyListener(null);
the EditText serves as some kind of log box, text is appended to it at some events.
I need the EditText to be scrolled to the right at all times, I mean the scrollbar should be positioned to the maximum right and so the most recent text is visible.
I cant seem to get it done, not sure how to read the current position of the scrollbar and adjust it accordingly.
I've tried playing with EditText.setScrollX() though even setScrollX(10000) didnt have any effect.
try with
editText.setSelection(editText.getText().length()-1);
I have a somewhat complicated layout, but at the very bottom is a huge EditText. When I click on it to get the keyboard to open, everything slides up just enough to show exactly where the user is typing (as the user begins typing only 1 line is visible, if the user goes to multiple lines then it pans a little more to show 2 lines, etc). I would like everything to pan so that the whole EditText (all the blank space) is visible.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:orientation="vertical">
<EditText
android:id="#+id/CommentBox"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:textSize="16sp"
android:layout_marginLeft="6dp"
android:layout_marginTop="4dp"
android:background="#color/transparent"
android:textColor="#color/gray"
android:gravity="top"
android:inputType="textMultiLine|textCapSentences|textShortMessage|textAutoCorrect|textNoSuggestions">
</EditText>
</LinearLayout>
Been struggling with this for a couple days now, would appreciate any suggestions.
Best way to illustrate is with 3 images
This is what the entire screen looks like
This is what the behavior is right now
This is the desired behavior
Hopefully the images illustrate my question. I need to figure out how to make this happen. The only way I have been able to force view to pan to the right place is by setting, android:gravity to bottom , in which case text is written at the bottom. This however, is clearly a very weird user experience. I need text to be like in a normal text box.
Was able to hack together a solution that mimics what I was looking for.
Put the layout inside a scrollView, set the parameter to adjustResize instead of adjustPan. And on click in the editText did
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, scrollView.getBottom());
}
} , 250);
Would love to find a non-hacky way to do this, but this is all I've got.