Android: Put EditText on top of WebView

最后都变了- 提交于 2020-01-25 05:37:25

问题


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 ?


回答1:


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)



回答2:


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.



来源:https://stackoverflow.com/questions/5059704/android-put-edittext-on-top-of-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!