My application playing HTML promotions in WebView, Html promotions having text so if user press long click android standard dialog appear Copy/Share/Find/Web Search, so is there any option to disable text selection dialog for webview ?
Help me on the same.
You need to do this way:
WebView webView = (WebView) findViewById(R.id.webView);
webView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
return true;
}
});
webView.setLongClickable(false);
// Below line prevent vibration on Long click
webView.setHapticFeedbackEnabled(false);
Hope this will help you.
Related
I'm developing a simple web browser that has Buttons on top of a WebView. These buttons work as text input shortcuts customizable by the user. Let's say the user types a lot "1234567890", he can set that text in a button shortcut and every time he taps it, the text is sent to the WebView. To accomplish this I'm using BaseInputConnection.
My problem is that the text is not sent to the WebView. But if it's a shortcut for a key press it works.
This is what I have:
private WebView wv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browser);
wv = findViewById(R.id.wvMain);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
wv.setWebViewClient(new WebViewClient() {
...
}
...
}
public void onShortcutButtonClick(View view) {
Shortcut sc = (Shortcut) view.getTag(); // Shortcut is a custom class that holds the type and text of the shortcut among other stuff.
switch (sc.getType()) {
case Shortcut.TYPE_KEY: {
BaseInputConnection inputConnection = new BaseInputConnection(wv, true);
inputConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0)); // Works! "0" is sent to whatever field the cursor is in the page of the WebView.
}
break;
case Shortcut.TYPE_TEXT: {
BaseInputConnection inputConnection = new BaseInputConnection(wv, true);
inputConnection.commitText("1234567890", 0)); // Doesn't work.
}
break;
...
}
}
sendKeyEvent works but commitText doesn't. I don't know if this is the best way to send text to a WebView. I also tried sending the text to the active element of the page using JavaScript but it doesn't work most of the time.
I have a webview and "Submit" button in my android app. Webview loads a url, and on clicking submit button both submit button and webview are hidden revealing a textview and "Go" button..
in submit button's onClickListener I have removed the webview as follows.
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
webview.setVisibility(View.GONE);
submit.setVisibility(View.GONE);
mytextview.setVisibility(View.VISIBLE);
go.setVisibility(View.VISIBLE);
}
}
This works fine..
In my go button's onClickListener I am loading the new url for this webview as follows
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
webview.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webview.setVisibility(View.VISIBLE);
mytextview.setVisibility(View.GONE);
webview.loadUrl("http://www.example.com");
}
}
Here textview disappears but it's not loading the webview. Only a blank screen appears...
Is it anything missing in my code..
Can you try keeping the below two lines.
webview.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);`
I believe this will fix your issue.
Acually i wanted to load the content in the webview , which is in a xhtml file .
I want to disable the accessibility to the content . Click on the link/texts must not navigate to that particular page .
More particularly , I have the contents page of a book in the xhtml file and click on the contents must not navigate to the particular page .
WebView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
Will work good but this stops the doulble tap zoom as well . I want to stop accessing the content without affecting the tap zoom .
And one more is that , what does webview.getSettings().setAllowContentAccess(false); refer to in webview .
Thanks in Advance .
If you only want to prevent navigations (user following links) then you need to use the shouldOverrideUrlLoading API:
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
});
I am new to Android and I have to create one android application that shows the images from the server. I want to apply zoom effects on button click. I have two buttons one for zoom in and another is form zoom out. I want to apply zoom in or out on click of related button click. I searched a lot but did not find any thing related to my specific case. I have so far implemented imageview.onTouchlisterner() for zoom effects but I don't want this I want to do zoom on button click so please help me. Thank you in advance.
a very simple technique that i used for such purpose, make a webview and load you image using its url into that webview on image clicked like this:
WebView web=(WebView)findViewById(R.id.web);
mProgress = ProgressDialog.show(this, "Please wait!", "Loading image and zoom controlls...");
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
web.getSettings().setBuiltInZoomControls(true);
WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(true);
String url=getIntent().getExtras().getString("imageURL");
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
// when finish loading page
public void onPageFinished(WebView view, String url) {
if(mProgress.isShowing()) {
mProgress.dismiss();
}
}
});
web.loadUrl(url);
}
I have a webView that is contained within a scrollView. Everything is then contained within a viewPager. When I fling to the next view page, the links that are in the middle of the page are being focused (highlighted with orange around the text). This causes the page to jump down to the nearest link.
Is there a way to disable links from being focusable on touch? I've tried all the settings for the webView such as focusable = false, clickable = false, focusable in touch mode = false, and nothing seems to be working.
I managed to do it programmatically like so:
WebView myWebView = (WebView) storyItem.findViewById(R.id.myWebView);
myWebView.setFocusableInTouchMode(false);
myWebView.setFocusable(false);
This makes the links non-focusable, which solved my problem!
webView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
Webview.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
});
This prevents the webview from opening any links and will also allow you to navigate the page without problems