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.
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 an EditText that is focused and a Button that is not focused.
When I click the Button, the EditText loses focus.
When I long-click the Button, the EditText does not lose focus.
Whats the source of this behaviour? I want to achieve the long-click behaviour within a default click, is this possible?
Long click behavior is for by default for ClipBoard actions . If you want to override it with Single click . You can do this as follows.
editText=(EditText)findViewById(R.id.txt);
editText.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// Do your stuff
return true;
}
});
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
editText.performLongClick();
}
});
If you are doing it to just get rid of Focusing problem then its not the way.
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);
}
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.
I would like to make an app, that shows a part of the site.
Lets say that i have this site:
I only want to show this:
https://mail.google.com/mail/?ui=2&ik=d5146163e8&view=att&th=132496ec47863fea&attid=0.1&disp=inline&realattid=f_gsbtyog80&zw
Is there anyway to do this?
I hope some of you could help me.
Gaauwe
You could load the url to a WebView and then set the WebView's scroll position and zoom level to display only a specific part of the web page. If you don't want to change zoom level you could initially scroll the WebView to the required location and then override the WebView's onTouch method so that it will only scroll upto the required cordinates.
public class MyWebViewActivity extends Activity implements PictureListener{
private WebView webView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView)findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new MyWebViewClient());
webView.setPictureListener(this);
// disable scroll on touch
webView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return (event.getAction() == MotionEvent.ACTION_MOVE);
}
});
webView.loadUrl(url);
}
#Override
public void onNewPicture(WebView view, Picture picture) {
// TODO Auto-generated method stub
webView.scrollTo(x, y);
}
}
One of the way is to use PHP on your own server and CURL the webpage into it and strip out all the unnecessary things .
After that you only load it into your webview.
*This is one of the method, there are others method better then this. *
Another way is coldfusion cfhttp .. not sure,about this http://www.quackit.com/coldfusion/tutorial/coldfusion_http.cfm