Hi,
Android 4 (ICS) offers a view element called ActionBar. Using the ActionBar, I've created a search widget where I can enter text to trigger a remote suggest search. If you click on a magnifier icon within this ActionBar to open the search widget textfield, two things happen:
The softkeyboard gets displayed
The "home button" (app icon on the top left) changes his
functionality to an "up button". "up" means, that you undo your last
action (in this case: opening the search widget textfield)
If you click on the "up button" the search widget collapses so that the textfield disappears. In the same moment the "up button" changes it's functionality back to act as a "home button". This behaviour describes the "default" behavior of the Android 4 ActionBar with an attached search widget.
Using the hardware "back button" instead of the soft "up button", the keyboard disappears, but the search widget remains open. Also the "up button" doesn't change to a "home button".
My question:
How can I trigger a "up button" click within the ActionBar programmatically? If I could do this, I could collapse the search widget textfield and put back the "up button" to become a "home button" again, if the user presses the hardware "back button".
This example shows a "home button" on the very left and a closed search widget "magnifier icon" on the right. If the user clicks the magnifier, the textfield shows up and the "home button" becomes a "up button".
Thanks in advance!
I think there can be a solution for this. As documentation says,
To navigate up when the user presses the app icon, you can use the NavUtils class's static method, navigateUpFromSameTask().
So you can manually call
NavUtils.navigateUpFromSameTask(this);
for performing home button click programmatically.
I have scoured the net and SO, and can't find any way to fire this programmatically.
I ended up just recreating the bits and pieces needed to make the view switch back to the home view along with changing the actionbar back to normal and putting that in a public method so other classes can make the view go home.
You can trigger a click on any view programmatically by calling performClick() on the View.
See the performClick() documentation.
Related
I am working on Android accessibility, and the phone has TalkBack enabled.
I have a screen with a toggle switch, and clicking on it will show a dialog.
Once the dialog is dismissed, the focus is supposed to go back to the toggle button and announce the content description for the button. But TalkBack is announcing, "Back. Toggle button is on."
I don't see the focus moving to the back navigation but somehow, it gets announced. And when the focus is in the navigation button, it always announces "Back button", but in the previous case, it's just "Back."
Things I already tried:
Force-focus the the toggle using request focus, sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED.
Interrupt - AccessibilityManager.interrupt()
Nothing worked!
Any clue why this would happen?
Toggle switch is on
Some newer Android devices have removed the hard Home Button and replaced it with a soft pop up navigation bar at the bottom of the screen that appears when the user swipes up. I've found that the Home Button can also be accessed by hard pressing (not just long clicking, kind of like iOS force touch) the area where the Home Button would appear if navigation bar is visible. This action triggers an onClick event within the current application before navigating to the device home screen. How can I prevent the onClick event within the application?
You can see in the image below how the navigation bar Home Button overlays the app button. Thanks for any help, I feel like i'm missing something really obvious.
I have a custom QuickAction menu in my app. I have added contentDescription "Open Menu" for the ImageView which opens the menu. So my TalkBack(form the Accessibility settings) announces the same. The popup menu has setOutsideTouchable(true) to dismiss it when touched outside. When TalkBack is On user has to double tap to dismiss it but Android does not announce any such message. Ideally, it should announce "Double tap to dismiss ...". How can I achieve this ? Also, I would like to announce when the menu is dismissed. I have tried sending AccessibilityEvent inside:QuickAction.setOnDismissListener(new myQuickAction.OnDismissListener() {
#Override
public void onDismiss() {
// tried sending event here
} Added reference image to explain in detail. On clicking button blue popup is the QuickAction popup. Now I want to announce "Dismiss Menu" when user tap anywhere(black dot) on white region. White region is actually my LinearLayout containing header, footer etc.(that are not shown in the image). I have tried adding the contentDescription, importantForAccessibility for the layout but to no avail.
I would add either a little "X" box, or if you don't want to mess up your UI, make your layout container focusable, and add the content-description "Double Tap to Dismiss". (Note: The double tap is a talkback gesture, don't add this, just replicating from your question.)
EDIT: Essentially, what I'm recommending, is instead of adding an "X" button to the view, allow the layout view to act as an "X" button itself. By adding a contentDescription to the layout, you are making it focusable, even though typical users wouldn't interact with this view, nothing is keeping TalkBack users from doing so. Thus you do not change your layout visually, but still have the accessibility benefit of a separate close button, even though technically speaking this is not necessary, as users should understand how to close modals without it.
I don't believe announcing that it has been dismissed is necessary. Shifting focus back to the element that was focused before you opened the modal is the typical approach. Have this happen after your double tap, and TalkBack users will know the menu was dismissed, because they are back in the main view, on the element that opened the modal.
Sidenote: Ensure your QuickAction behaves as a modal!
When using a floating view (TYPE_PRIORITY_PHONE) how can the Home button be intercepted?
This behaviour is demonstrated in Facebook's "chat heads" where a conversation (which isn't an Activity) is collapsed on a home button click.
You could poll the top running app, and determine when it changes. This will detect the first home press, but if the users is already on the home screen, you will not detect it.
I have an android application where I want to display a LinearLayout when user clicks on options button(I am setting the linear layout's visibility to visible in onCreateOptionsMenu) and make it invisilble when user clicks on back button.
This works fine when I press the option button and then the back button-the view comes up and then goes away respectively.
The problem is when I press the option button again, the linearlayout does not show even though the visibility is being set to visible.
However, log tells me that the methos onCreateOptionsMenu is entered.
Why would this happen?
onCreateOptionsMenu is called only once per activity. In your case you have to code in onPrepareOptionsMenu. This will be called every time the user presses menu key.
Why do you want do this? For android users relevant reaction for menu button is option menu.
What about question, try use View.bringToFront() - it will bring view in front of all views of the same parent.