I have tried calling
zoomIn();
setBuiltInZoomControls(true);
supportZoom(true);
etc but it just wouldn't work.
Just a hint... when I double-click on the text it does fit the screen but no wrap.
Any lead given will be deeply appreciated.
Have you added a Viewport Meta tag?
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
If the HTML body is set to 100%, the text should automatically fill the screen.
Hi try the following code :
public class Terms extends Activity {
WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.terms);
this.mWebView = ((WebView)findViewById(R.id.mWebView));
this.mWebView.getSettings().setBuiltInZoomControls(false);
this.mWebView.getSettings().setLoadWithOverviewMode(false);
this.mWebView.getSettings().setUseWideViewPort(false);
this.mWebView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
this.mWebView.loadUrl("file:///android_asset/Terms.html");
Button back_btn = (Button)findViewById(R.id.back);
back_btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View view)
{
finish();
}
});
}
#SuppressWarnings("unused")
private class Callback extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return(false);
}
}
}
Related
I am trying to set text in java file.
this is my xml code
.xml file
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
this is my java code
java file
public class account extends AppCompatActivity {
TextView textview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
textview = (TextView)findViewById(R.id.text);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
public void onLoadResource(WebView view, String url) {
textview.setText("Register");
}
});
}}
issue is if i set title in oncreate it's work fine but if set in onLoadResource then it's not working.
This site works well in android browsers but it doesn't work in android webview.
I set internet permission and did all things.
Who can teach me?
public class MainActivity extends AppCompatActivity {
WebView web_view;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OneSignal.startInit(this).init();
setContentView(R.layout.activity_main);
web_view = (WebView)findViewById(R.id.webView);
getSupportActionBar().hide();
web_view.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
web_view.getSettings().setDomStorageEnabled(true);
web_view.getSettings().setJavaScriptEnabled(true);
web_view.setWebViewClient(mWebViewClient);
web_view.addJavascriptInterface(new MyJavaScriptInterface(), "android");
web_view.loadUrl("http://182.72.55.182/pms/employee");
}
WebViewClient mWebViewClient = new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:window.android.onUrlChange(window.location.href);");
};
};
class MyJavaScriptInterface {
#JavascriptInterface
public void onUrlChange(String url) {
Log.d("hydrated", "onUrlChange" + url);
}
}
}
make sure that your regarding website becoming live in everywhere!
webview doesn't display any local host website
Try to put WebViewClient part inside the onCreate.
Hey guys I want to surf internet from webview in android and i am getting the page for which i have provided url in edittext.But when click on a link inside webview then it is unable to find that page.I have provided internet permission in manifest file and taken web view in layout.
This is my main activity which needs to be corrected somewhere.Thanks in advance and help done will be greatly appreciated.
public class MainActivity extends Activity {
EditText et1;
Button btn;
WebView wv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=(EditText) findViewById(R.id.et1);
btn=(Button) findViewById(R.id.btn);
wv=(WebView) findViewById(R.id.wv);
wv.setWebViewClient(new mybrowser());
btn.setOnClickListener(new OnClickListener() {
#SuppressLint("SetJavaScriptEnabled") #Override
public void onClick(View v)
{
String url = et1.getText().toString();
wv.getSettings().setLoadsImagesAutomatically(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv.loadUrl("https://"+url);
wv.requestFocus();
}
});
}
class mybrowser extends WebViewClient
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
String url1=et1.getText().toString();
view.loadUrl(url1);
return true;
}
}
}
Try to do like
class mybrowser extends WebViewClient
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
}
and remove String url1=et1.getText().toString();
i have a problem with loading a webview from a string url.
here is the code of an activity with only WebView.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
Intent intent=getIntent();
String url=intent.getStringExtra("url");
//EditText edit=(EditText)findViewById(R.id.editText1);
//String url=edit.getText().toString();
WebView webview=(WebView)findViewById(R.id.webView1);
webview.loadUrl(url);
webview.setWebViewClient(new WebViewClient());
}`
and code of the calling activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onGo(View v)
{
EditText edit=(EditText)findViewById(R.id.editText1);
Intent intent=new Intent(MainActivity.this,WebActivity.class);
intent.putExtra("url", edit.getText().toString());
startActivity(intent);
}
i have even added the android.permissions.INTERNET in the manifest
but still i cannot view the page with the click of the button in MainActivity.
From the comment
yes the real device has the same error with "www.google.com"
Use
http://www.google.com
Also make sure you have internet permission mentioned in manifest file
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
I am using loadDataWithBaseURL() to display the contents on WebView.
I need to refresh my WebView on clicking next button, please help me out in this concern.
Here is my sample code
public class screen extends Activity
{
WebView browser;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.temp);
browser = (WebView)findViewById(R.id.WebView01);
browser.loadDataWithBaseURL("", "<HTML><BODY>Here we are<P>1</P><P>2</P><P>3</P><P>4</P><P>5</P></BODY></HTML>", "text/html", Encoding.UTF_8.toString(),"");
next.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
screen.this.browser.loadDataWithBaseURL("", "<HTML><BODY>Here I am</BODY></HTML>", "text/html", Encoding.UTF_8.toString(),"");
}
});
}
}