TextView does not get focus on talkback mode - android

I have an fragment in android TV application which has a lot of TextViews, some of them are focusable and the others are not.
When I turn on the talkback on the device, the views which are not focusable does not get accessibility focus, so their texts are not read to the user.
For example, here is a sample TextView I've inserted to the layout and it is not get focused while on talkback mode:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginBottom="40dp"
android:contentDescription="This is the content description"
android:importantForAccessibility="yes"
android:text="This is the text" />
Of caurse that I don't want to add android:focusable="true" since it will make it focusable also when not on talkback mode.
Is there any thing I am missing that cause this view not to get focus when on talkback mode?
Thanks

You can request focus in talkback mode by following java method.
Trying adding this:
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
from Android P onwards, You can also try this
android:screenReaderFocusable
OR
view.setScreenReaderFocusable(boolean)

Related

Android: TextInputEditText showing text only after change focus

I have a big problem with a EditText that does not show any input until i change focus from element. When I click on the input, the keyboard appears and while i type, there is nothing displayed in the edit text view. The input is shown only when i close the keyboard
It is not a problem of colours. I mention that the view are contained in a constraint layout. I can enable hardware acceleration but this will slow down the application very much and it's not an option. I can however discard the constraint layout and change it to a linear layout but this will affect the rest of the code. I am sure that I am missing something, an easy fix, but i can't put my finger on it. Thanks a lot in advance
<android.support.design.widget.TextInputLayout
android:id="#+id/codeEditTextContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toTopOf="#id/verifyButton"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<android.support.design.widget.TextInputEditText
android:id="#+id/codeEditText"
android:layout_width="match_parent"
android:inputType="text"
android:layout_height="wrap_content"
android:hint="#string/sms_code"
android:padding="10dp"
android:textColor="#color/white" />
</android.support.design.widget.TextInputLayout>
!!UPDATE
Found the problem, but still i have no answer. This problem is present only on Android Pie and only when the edit text is in the lower part of the screen and has to be raised by the soft keyboard. I already tried to add softInputWindowMode to adjustResize or adjustPan but this is not doing anything.
The problem itself is a duplicate to this question Android Pie edittext does not adjustPan/resize while typing
which still doesn't have an answer
The problem man be about hardwareAccelerated. I was having the same problem and waste too much time to solve before saw this page.
Android Pie edittext does not adjustPan/resize while typing

Navigate between headings with swipe while using talkback

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.

How can I make TalkBack ignore android:text element?

I am improving the accessibility for visually impaired in my android app. I have the following TextView in a popover.xml file in my Android project.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:text="#string/pass_code"/>
Whenever I test the app with TalkBack, the app speaks back the string in android:text but in this case I don't want it to be spoken at all because this is a popover window so I would rather want it to be spoken as soon as the window pops over. So I've got android:contentDescription="#string/pass_code" in my root LinearLayout which speaks out the same string.
I've tried to set android:contentDescription="#null" and I've also tried adding tools:ignore="ContentDescription" but neither of them worked. The element in android:text is always spoken. How can I change the TextView so TalkBack will ignore the android:text element?
You can hide a view from accessibility services by setting android:importantForAccessibility="no" in your layout XML. See the developer docs for View.setImportantForAccessibility(int) for more details.

How can I use a custom font in the input area of an input method?

We're developing an app where we need to use a custom font (a Typeface loaded from the app's assets) in an EditText. The Android input method docs state the following:
When input focus moves into or out of an editable text field, Android shows or hides the input method (such as the on-screen keyboard) as appropriate. The system also makes decisions about how your UI and the text field appear above the input method. For example, when the vertical space on the screen is constrained, the text field might fill all space above the input method.
It's the part in bold that is tripping us up. The phrase “the text field might fill...” appears to be misleading, in that the text field that's used is not the EditText that we set up with our custom font. (NOTE: the answers so far all explain how to set a custom font in an EditText. We already are setting a custom typeface in the EditText. Please read the question carefully before answering.) Here's a screenshot with the input method hidden:
Here's what happens when the soft keyboard is showing and vertical space is constrained:
As you can see, the font in the text field above the input method is not our custom font (I'm guessing it's the system's default Roboto font). This is happening for every soft keyboard we've tried as the input method.
I want to emphasize that when space is constrained, this view above the keyboard is generated internally by the system, not by any of our code.
The main question is: Is there a way (and, if so, what is it?) to control the appearance of this (for lack of better terminology) proxy view—at a minimum to get it to use our custom font?
It would be an added bonus if we could also control the layout and appearance of the entire proxy area above the keyboard (including the "Done" button). We are using a variation of the technique described in this thread to have our activity use a locale different from the one set in the system, but the activity's locale clearly isn't being applied here. (If it were, the button would be on the left and would read "בוצע", as does happen if I change the device's locale to Hebrew. [EDIT: I can get the correct button label by using the android:imeActionLabel attribute on the EditText. However, I don't know how to control the layout directionality.])
EDIT Per request, here's how I'm constructing my dialog (relevant parts excerpted from a DialogFragment):
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Dialog dlg = new Dialog(getActivity(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar);
dlg.setContentView(R.layout.edit_note_dialog);
mAnimator = (ViewAnimator) dlg.findViewById(R.id.animator);
final Typeface hebrew = SystemData.getHebrewFont();
mNoteEditor = (EditText) dlg.findViewById(R.id.note_field);
mNoteEditor.setTypeface(hebrew);
// etc. (setting fonts for other elements, adding listeners, etc.)
}
And here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<ViewAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/animator"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="#string/loading" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#android:color/black"
android:gravity="center"
android:text="#string/edit_note_title"
android:textColor="#android:color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/citation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerHorizontal="true"
android:background="#android:color/black"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="16sp" />
<LinearLayout
android:id="#+id/actions"
style="?android:attr/buttonBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="5dp" >
<Button
android:id="#+id/cancel"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:gravity="center"
android:minWidth="32dp"
android:text="#string/cancel"
android:textSize="#dimen/nav_interior_item_size" />
<Button
android:id="#+id/close"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="center"
android:minWidth="32dp"
android:text="#string/save"
android:textSize="#dimen/nav_interior_item_size" />
</LinearLayout>
<Button
android:id="#+id/undo"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_margin="5dp"
android:text="#string/edit_note_undo"
android:textSize="#dimen/nav_interior_item_size" />
<Button
android:id="#+id/redo"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_margin="5dp"
android:text="#string/edit_note_redo"
android:textSize="#dimen/nav_interior_item_size" />
<EditText
android:id="#+id/note_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/actions"
android:layout_below="#+id/citation"
android:focusableInTouchMode="true"
android:gravity="top"
android:hint="#string/edit_note_hint"
android:imeActionLabel="#string/done"
android:inputType="textMultiLine|textNoSuggestions"
android:lineSpacingMultiplier="1.2" />
</RelativeLayout>
</ViewAnimator>
It would be simple if you had an instance of InputMethodService.
There is a way to set a theme or even set extracted view.
The problem is you have to create a custom implementation of Input Method and users will have to select it in the system settings.
Update:
You can try with:
android:windowSoftInputMode="adjustResize"
make the view scrollable
or
use IME_FLAG_NO_EXTRACT_UI
set an OnEditorActionListener on the EditText to have an action button on the keyboard.
create custom layout or hide/show elements when screen's height is too small. For example hide buttons at the bottom and show buttons on right side. It can look similar to the default extract view.
layout listener for the dialog or EditText:
mViewContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
//unregister the layout listener if needed.
int heightPixels = mViewContainer.getHeight();
Resources resources = mContext.getResources();
int heightDip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, heightPixels, resources.getDisplayMetrics());
if (heightDip < MIN_HEIGHT) {
mBottomButtons.setVisibility(View.GONE);
mSideButtons.setVisibility(View.VISIBLE);
} else {
mBottomButtons.setVisibility(View.VISIBLE);
mSideButtons.setVisibility(View.GONE);
}
}
});
Changing the visibility to GONE will request relayout and the listener will run again what can lead to a loop.
The only way I can see is to disable the fullscreen editing mode for your EditText that automatically kicks in when your EditText is not tall enough.
mNoteEditor.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
You can fix the dialog resizing issues with
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Your dialog layout should probably be enclosed in a ScrollView.
I think as other have stated this is unfortunately up the IME and may not be possible through supported APIs.
Beware, hacky and untested solution incoming:
Digging through the Android source code, I found that every IME contains an implementation of AbstractInputMethodService. Android provides a standard implementation (android.inputmethodservice.InputMethodService) which if you look at, has a public setExtractView method, and an onCreateExtractTextView method, which inflates com.android.internal.R.layout.input_method_extract_view.xml, which in turn contains com.android.internal.R.id.inputExtractEditText! So a hacky solution would be to hope that most of your customer's IMEs' InputMethodServices use this same XML (which as far as I can tell, has been in Android for a while), and you can attempt to grab a reference to this EditText by it's ID and change it's typeface. Unfortunately I'm not sure offhand where in the view hierarchy/window the views of an InputMethodService are added, and if they're accessible from your app/activitys process.
Source for InputMethodService:
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/inputmethodservice/InputMethodService.java
Source for the layout XML:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/input_method_extract_view.xml
If you really want to get yourself in trouble, perhaps there's a way to get a reference to the IME service itself, and use reflection to alter the extracted view. The standard InputMethodService holds a package-private reference to mExtractEditText :)
I know not the answer you're looking for but perhaps it'll put you in the right direction...or some direction at least.
If you have a single editable element on your Dialog, how about handling orientation changes and
in case of Portrait orientation, show the Dialog
in case of Landscape orientation, show a fullscreen Fragment with the EditText and Buttons (as others have stated; disable fullscreen editing mode for the EditText), request focus for the EditText, show Keyboard.
in case of orientation switching dismiss Dialog / show Fragment with the already entered text (and vice versa)
This might be conceptually good because if the user wishes to enter text, he/she will always end up in a fullscreen editing layout in Landscape orientation. And since there is only one editable view in the original Dialog, you don't explicitly need the Dialog to select anything else to edit (another EditText for example).

How to enable IME word auto-suggest in an Android EditText?

I have a text field and when I use the IME (the default one for Nexus One) it doesn't display the auto-suggest line on top of the soft keyboard.
Ironically there are posts here on how to prevent the auto-suggest, but in my case it's the revert, it doesn't show up and it's not clear why.
Here's my layout tag. I'm in API 8.
<EditText
android:id="#+id/user_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="top"
android:singleLine="false"
android:inputType="textLongMessage|textCapSentences|textMultiLine|textAutoCorrect|textAutoComplete"
android:hint="#string/errorreport_user_hint"
android:paddingLeft="5dip"
android:paddingRight="5dip"
/>
Ah got it, I should not use the textAutoCorrect flag.
I thought it would ask the IME to display auto-correction, instead the doc indicates it means the editor is providing auto-corrections (I guess such as AutoCompleteEditText) and thus the IME should not display the auto-suggests.

Categories

Resources