Close button of "chrome custom tab" close the entire webview itself. However I want it to override its behaviour to work as hardware back button behaviour so that user can go back to previous page of web instead of closing webview.
I read so many posts and blogs but i could not get find any solution. I have found the solution to change the close button icon.
In my case my application does nothing but open the Chrome Custom Tab, so I was able to do this:
// This is called on boot, and when the Chrome Custom Tab's X button in the top left is clicked.
protected void onResume() {
super.onResume();
tryLaunch();
}
where tryLaunch launches Chrome
That's not currently possible.
Related
I currently have a webviewer in my app that works just fine, however, I wanted to see if there was a way to add the adressbar and a close button to the top of it. Kinda the same way Instagram does it, see image:
Right now, I have a close button but when scrolling through the webview that close button goes over the content of the website.
My current code:
btnOpenWebViewer.setOnClickListener{
btnCloseWebViewer.visibility = VISIBLE
webViewer.visibility = VISIBLE
webViewer.settings.javaScriptEnabled = true
webViewer.canGoBack()
webViewer.loadUrl("https://mysite/")
}
Several SO questions cover the topic of how to wire up a WebView to have the "back" button traverse browser history. An Android developer doc page answers that question well. We have an app that uses the recommended method:
#Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
return;
}
// Otherwise defer to system default behavior.
super.onBackPressed();
}
And that works fine. But the doc page also cautions,
Be careful when using this mechanism with highly dynamic web pages
that can grow a large history. Pages that generate an extensive
history, such as those that make frequent changes to the document
hash, may make it tedious for users to get out of your activity.
Our client has confirmed that this is a problem: When following over a dozen successive links within a WebView, getting back out to the previous (parent) activity is tedious, especially because you have to wait between taps of the back button for the WebView to refresh.
Unfortunately the developer doc page doesn't suggest a workaround for this situation.
One possibility is to use the "up" button in the toolbar/appBar/actionBar to exit the WebView.
My concern with that is that the "up" button normally looks like a backward-pointing arrow or chevron, very similar to the "back" button (identical to the "back" arrow in some browsers). So then we'd have an "up" button in the toolbar and the Android "back" button, looking very similar and doing something different. That would seem confusing to the user.
Is there a better way to provide "exit" navigation from a WebView besides the "back" button?
(Not a duplicate: using phones back button to exit from webview asks how to get the "back" button to exit the WebView only after there's no more history to traverse back over.)
One possibility is to use the "up" button in the toolbar/appBar/actionBar to exit the WebView.
What else would you have in the toolbar? What would it do?
Usually every screen that is not the root has a home (up) button in the toolbar that closes the screen again. That's how most Android apps work.
My concern with that is that the "up" button normally looks like a backward-pointing arrow or chevron, very similar in concept to the "back" button (identical to the "back" arrow in some browsers). So then we'd have an "up" button in the toolbar and the Android "back" button, looking very similar and doing something different. Is that a recipe for confusing the user?
That's Android and if you do it that way you follow the platform guidelines. As mentioned above, that arrow in the toolbar is in almost every app and navigates away from the current screen, whether its called home, back, up, or something else.
But you're right, back and up gets confused a lot.
An alternative is to opt for the close style. Replace the default arrow by an ✖ and its action closes the current screen should be evident.
While I prefer the Up arrow, the ✖ is a valid alternative, especially if you pop some WebView for additional content and want a strong indicator on how to close it again.
Is there a better way to provide "exit" navigation from a WebView besides the "back" button?
Nope. You could try asking on UX Stack Exchange, but you already have 2 platform standards—namely back and up—that can and should be used for navigation.
Anything else that you might come up with would be "new" and unique to your app, but of course you could just add a "Close Screen" button.
tl;dr If you don't like the Up Arrow in your toolbar use an ✖ as a close icon.
I am making a webview client app for my RSS website. The webview and splashscreen are working great in theme.notitlebar.fullscreen.
Because external links are opening in my webview, i want a back button in the titlebar. But i want to keep the full screen option, to remove the time and notifications, and the device buttons.
What i dont understand: Is it correct that the titlebar includes: the bar with time and notifications - bar with app name, back button and settings (extra) button - the device buttons (if available)?
If that is right. How can i add a new bar into the mainactivity with my webview client, with a back button in it.
I hope you understand my question.
You can use image view. set src to back icon. and finish(); activity on imageview click.
I would like to be able to hide the content of the app when it is not in foreground, for example, when I click the overview button(task list), the Chase banking app would just show pure solid color and hide all the content. Does anyone know how to do this?
I found out the answer should be add the following in onCreate of activity. This also block user from taking screen shots of the activity.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
You can override onStop method in an activity and make the view invisible.
In my application there are some buttons that are very near to that device default back button and Menu Button.
Thus I got problem while pressing that My application button which are near to Menu and Back button.
So for that application purpose I want to disable the default back and Menu Button.
So does Android Application development Guideline allow if we want to disable the back and Menu Button during particular application?
If yes then how is it possible?
Thanks.
So is Android Application development Guideline allow if we want to disable the back and Menu Button during perticular application?
The guideline of programming for any OS (Windows, Mac, iOS, Android etc.) is don't break the default behaviour.
A user will expect that your App supports the default behaviour of the device he/she is using and in most cases bought the device for that very reason: He/she enjoys the default behaviour. If he/she wanted another type of user interaction, he/she would have bought another type of device.
In my application there are some buttons that are very near to that device default back button and Menu Button
As long as your button is on the screen, I don't see how it can become a problem. If however it in someway is a problem, a better solution than overriding default behaviour is to move or enlarge your buttons to make it easier for the user to hit them.
If yes then how it is possible?
Yes, it can be done.
To disable the back button, simply override onBackPressed() in whatever Activity the problem occurs and leave the implementaion of it empty:
public void onBackPressed() {
//Do nothing
}
The Menu Button will only be a problem ifyou inflate a menu from your Activity. Standard behaviour is that nothing happens when you hit the Menu Button as long as you don't tell your Activity to do something.
Sometimes you'll want to override the default behaviour, fx if you use views and the user expects onback to navigate between views. Other times something else, it all depends on the application. I'd recommend to consider if you should override default behaviour or not.
Heres another example that can be used for all the buttons:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && (isSomething)) {
something();
return true;
}
return super.onKeyDown(keyCode, event);
}