Android Quick Return Pattern Webview - android

I want to use the quick return pattern which is described here:
http://www.androiduipatterns.com/2012/08/an-emerging-ui-pattern-quick-return.html
When i use a webview this webview must have the fullscreen height of the device to implement it correctly. Then i have to inject a paddingTop to the body tag on the html in the webview to get the correct margin/padding from top. But there is a problem if the toolbar isnt shown and the site loads new content with javascript which cant scroll. First there is a ugly white area on the top off the webview and second the toolbar cant get shown because the site cant scroll.
Is there any best practice for this behaviour?
Is the javascript injection the correct way?

Related

Android: how to show the user which view is active

I have an activity with a WebView. I would like to give the possibility to the user to scroll from one WebView to another WebView (as it's done to Android desktop):
with something in the bottom which shows which screen is actually viewed. I have think about the ScrollView but maybe something else exists which easier to use.
what you want to use is the ViewPager
http://android-developers.blogspot.de/2011/08/horizontal-view-swiping-with-viewpager.html
To get an indicator which shows on what page the user is use:
http://jakewharton.com/viewpagerindicator/
An example how to use it is here:
http://blog.stylingandroid.com/archives/537

How do you create the Browser layout (search bar on top, webview on bottom)?

I'm trying to mimic the default android Browser app layout, which has a "search_bar" on top and then a "webview" right below it. The user can scroll both items up, all the while the scroll bar only appears to the right of the webview (not both the webview and the search bar).
I've tried putting both the webview and the searchbar into a scrollview, but this shows the scrollbar next to the search_bar.
If you need to mimic the exact layout of default browser have a look at it's source code:
Where can I find Android source code online?
If you need only browser source have a look here:
https://android.googlesource.com/platform/packages/apps/Browser
From what I can see (a quick look at it) it is more complicated layout, but you may start analysing it from:
Browser\res\layout\browser_subwindow.xml
which directly includes WebView. This file is directly loaded by Tab... Go ahaed and analyse it on your own it is pretty simple as it is a regular Android application.
Hope it helps.

Android Copying WebView to Webview

I am working on a webview with local html file as source.
I am trying to copy a Webview on to another webview.
If I do this.
WebView1.loadUrl(webView2.getUrl());
I works, but it is same as loading the webview again,which i dont want. If I do this
WebView1=WebView2;
It doesn't copy. The content of WebView1 doesn't change. Am I doing anything wrong.
You'll have to remove the current WebView from your Layout (by calling removeView(WebView1) on it's container) and then add the new WebView to it (addView(WebView2) on the same container). Obviously you'll have to take care that it gets inserted at the right place again. Easiest way would be to just wrap a FrameLayout around it and call said methods on it.
Can't promise you that this will work though, since I don't know how WebView behaves offscreen.

Android: Put EditText on top of WebView

I have been trying to mimic the behavior of the android browser with the scrolling of the address bar on top of the WebView. If you notice, if the user scrolls down, the address bar "moves" up with the WebView (but the WebView doesn't scroll). Only when the address bar disappears completely the WebView starts to scroll. At first I tried to override the onScrollChanged method of WebView, and got something but it wasn't as smooth as the desired goal. I noticed in the docs that WebView inherits from AbsoluteLayout, so I was wondering if it's possible to add a View programmatically on top the "browser" in the WebView and by that achieve the desired scrolling effect?
EDIT
Ok so after poking around in the source code of the native browser app, I found out that there is an hidden method for that called setEmbeddedTitleBar(View v)
And here is the description (from the Android source):
/**Add or remove a title bar to be embedded into the WebView, and scroll
* along with it vertically, while remaining in view horizontally. Pass
* null to remove the title bar from the WebView, and return to drawing
* the WebView normally without translating to account for the title bar.
* #hide*/
Do you know how I can hack my way to use this ?
You could probably still use reflection to access it. See:
Using Reflection for Backward Compatibility for Android (Android Developers)
Calling a Method Using Reflection (StackOverflow)
As far as I can see this method is public. So you can use it I think.
I've just looked through its implementation. It just calls addView() method of WebView object. So if you don't want to use hidden method you can reimplement this method.

scrolling vertically to a specific text part in a webview

I'm looking for a way to scroll a webview that a specific part of the contained text is shown.
Scrolling programmatically needs always an integer value of how far to scroll. Is there any possibility of retrieving the y-position of a specific text in that webview?
If you are the editor of the html content, you could simply use anchors inside the html :
The text I want to scroll to
and then simply use webview.loadurl("mywebpage.html#firstpart")
WebView has the findAll(String) and findNext() methods. They're not well documented though, and they seem to have some issues pre-froyo.
This thread in particular may help you give it a try, though. These find methods call native code, so it's not something you could easily override, I don't think. There might be something you could do with Javascript, but that's certainly not something I'm familiar with.

Categories

Resources