Próbuję uzyskać kontrolę zoomu, aby wyświetlać wraz z szczyptą, aby powiększyć do pracy w przeglądarce internetowej Android. W dużym stopniu odwołuje się do this SO.Android Włącz kontrolki powiększania i pomniejszania w widoku internetowym
Teraz mam te są ustawione w metodzie onCreate:
this._webView.getSettings().setBuiltInZoomControls(true);
this._webView.getSettings().setDisplayZoomControls(true);
this._webView.getSettings().setSupportZoom(true);
Ale nic nie pojawia się i kontrole zoom nie pojawiają. Próbowałem też bez setSupportZoom
, ale to nie pomagało.
O ile mogę powiedzieć moja WebView nie jest owinięty w widoku przewijania, ale jest podklasą Webview:
class MyWebView extends WebView {
public MyWebView(Context context) {
super(context);
}
@Override
public void goBack() {
super.goBack();
}
}
więc skończyć tworzenie go tak:
if (this._webView == null) {
this._webView = new MyWebView(this);
this._webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
this._webView.getSettings().setJavaScriptEnabled(true);
this._webView.setWebChromeClient(new WebChromeClient());
this._webView.setWebViewClient(new WebViewClient());
this._webView.getSettings().setBuiltInZoomControls(true);
this._webView.getSettings().setDisplayZoomControls(true);
this._webView.getSettings().setSupportZoom(true);
this._webView.loadUrl(this._baseUrl);
}
Jakieś pomysły, które idą źle?
Dzięki!
EDIT:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(1);
getWindow().setFlags(1024, 1024);
RelativeLayout my_layout = generateLayout();
initUI();
setContentView(my_layout);
}
W generateLayout tworzymy początkowy układ i tworzyć uchwyt dla Webview::
private RelativeLayout generateLayout() {
RelativeLayout my_layout = new RelativeLayout(this);
my_layout.setId(this.generateViewId());
my_layout.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT));
... more layout stuff
FrameLayout webViewPlaceholder = new FrameLayout(this);
this._webViewPlaceholder = webViewPlaceholder;
webViewPlaceholder.setId(this.generateViewId());
webViewPlaceholder.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
RelativeLayout.LayoutParams webViewPlaceholderLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
webViewPlaceholderLayoutParams.addRule(RelativeLayout.BELOW, rlHeader.getId());
webViewPlaceholder.setLayoutParams(webViewPlaceholderLayoutParams);
my_layout.addView(webViewPlaceholder);
}
Następnie w initUI
tworzymy
W onCreate
to zrobić sama przeglądarka internetowa:
@SuppressLint({"SetJavaScriptEnabled"})
protected void initUI() {
if (this._webView == null) {
this._webView = new MyWebView(this);
this._webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
this._webView.getSettings().setJavaScriptEnabled(true);
this._webView.setWebChromeClient(new WebChromeClient());
this._webView.setWebViewClient(new WebViewClient());
this._webView.getSettings().setSupportZoom(true);
this._webView.getSettings().setBuiltInZoomControls(true);
this._webView.getSettings().setDisplayZoomControls(true);
this._webView.loadUrl(this._baseUrl);
} else {
if (this._webView.getProgress() >= 100) {
this._progressIndicatorView.setVisibility(View.INVISIBLE);
}
setNavigationButtonsState();
}
this._webViewPlaceholder.addView(this._webView);
}
Myślę, że nie otrzymujesz odniesienia do widoku internetowego. Spróbuj użyć widoku internetowego jako widoku układu, a nie jest tworzony dynamicznie. –
Czy dodajesz "this._webView" do swojego układu? RootView powinien dodać przeglądarkę do swojego układu. – cole
Dodaję 'FrameLayout' do głównego' RelativeLayout', a następnie dodam do tego 'this._webView'. Główny układ jest programowo tworzony. Czy chcesz zobaczyć kod? –