Autosuggestion is not enable on webview using websetting - java

I have found it impossible to correctly set the autocompletion of fields in html forms in an android studio webview:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ProgressBar
android:id="#+id/progressbar_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" />
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:usesCleartextTraffic="true" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java:
package com.example.webview;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
private WebView myWebView;
private ProgressBar progressBar;
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = findViewById(R.id.webview);
progressBar = findViewById(R.id.progressbar_id);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setGeolocationEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setSaveFormData(true);
WebViewClient webViewClient = new WebViewClient(){
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progressBar.setVisibility(View.VISIBLE);
myWebView.setVisibility(View.GONE);
}
#Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
myWebView.setVisibility(View.VISIBLE);
}
};
myWebView.setWebViewClient(webViewClient);
myWebView.setSoundEffectsEnabled(true);
myWebView.loadUrl("https://tcg-wallet.ga/home");
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
}
i have try using:
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
but nothing happens there are no suggestions, I expected something like:
I don't know what I need to add to enable those suggestions!

Related

How to Set Linear Layout with WebView for onClickListener

I have a linear layout carrying webview. I have set the id of the LinearLayout to 'lay001'.
My intention is to set the onClickListener of the layout so that onclick, the intent will send data to webview and then to the url i specified.
All my efforts to make it work failed me. Please help me set the java code. Thanks
activity_main.xml
<LinearLayout
android:id="#+id/lay001"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:layout_margin="4dp"
android:orientation="vertical"
android:background="#drawable/layout_bg1">
<WebView
android:id="#+id/webview001"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:accessibilityPaneTitle="The Liturgy"
android:layout_marginTop="2dp">
</WebView>
<TextView
android:id="#+id/textView001"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:text="Anglican Hymns Tunes"
android:textSize="10sp"
android:textStyle="italic|bold"
android:textAlignment="center"
android:textColor="#DD1A1A"/>
</LinearLayout>
MainActivity.java
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private WebView webview;
private LinearLayout myLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myLayout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
webview = (WebView001) findViewById(R.id.webview001);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl("http://www.google.com");
}
}
});
}
}
You are missing findViewById() of linearlayout.
Try this out :
private LinearLayout myLayout;
myLayout= (LinearLayout) findViewById(R.id.lay001);
Also change this :
webview = (WebView) findViewById(R.id.webview001);
To load url :
myLayout.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
mWebview.loadUrl("your url");
}
});

toolbar not showing in webview?

I am developing an android news app and implemented toolbar as a back arrow when the user clicks should go to the back
I am developing an android news app and implemented toolbar as a back arrow when the user clicks should go to the back
below my DetailActivity where I have implemented toolbar
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import butterknife.BindView;
import butterknife.ButterKnife;
import edgar.yodgorbek.sportnews.R;
public class DetailActivity extends AppCompatActivity {
#BindView(R.id.toolbar)
Toolbar toolbar;
#BindView(R.id.imageView)
ImageView imageView;
#BindView(R.id.webView)
WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
String imageUrl = getIntent().getExtras().getString("imageKey");
Picasso.get().load(imageUrl).into(imageView);
webView.getSettings().setJavaScriptEnabled(true);
String url = getIntent().getExtras().getString("urlKey");
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
}
#Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
public class WebViewController extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
below my activity_detail.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:layout_marginTop="32dp"
tools:ignore="ContentDescription" />
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView" />
</android.support.design.widget.CoordinatorLayout>

I have some issue about WebView

I can't use WebView correctly. When I run my app there is "What to use" window and buttons "Browser, Chrome, Sorting" On Clicking "Отмена"/"Cancel" there is nothing happen. There are no errors in my code and I really don't know how to use WebView correctly. Please help me. "What to use" window
But I add WebView and I want to show everything in it. There is my code:
Main_Activity.java
package com.admin.zabroshki;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#SuppressLint("ResourceType")
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// получим идентификатор выбранного пункта меню
int id = item.getItemId();
String urlVK = new String("https://vk.com/zabroshkiborika");
String urlInstagram = new
String("https://instagram.com/zabroshkiborika");
WebView view = (WebView) findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setLoadWithOverviewMode(true);
view.getSettings().setUseWideViewPort(true);
switch (id)
{
case R.id.urlVK:
view.loadUrl(urlVK);
break;
case R.id.Instagram:
view.loadUrl(urlInstagram);
break;
}
return false;
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.admin.zabroshki.MainActivity">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
You try this.
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAllowContentAccess(true);
settings.setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://vk.com/zabroshkiborika");

Adding a progress bar to android webview java

please i am very new in android development, i have my website which i load in webview and is working now i want to add a progress bar to show when a link is processing to render and hide the progress bar after page is loaded.
please i have see a lot of examples but i kept on getting error while trying to implement it, please can someone help me using me own webview for example.
package com.mypage.mypage;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class SourceProjectActivity extends AppCompatActivity {
private WebView projectLoaderView;
private ProgressBar progress;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_source_project);
projectLoaderView = (WebView)findViewById(R.id.sourcejailview);
WebSettings webSettings = projectLoaderView.getSettings();
progress = (ProgressBar) findViewById(R.id.progressBar);
progress.setMax(100);
webSettings.setJavaScriptEnabled(true);
webSettings.setSaveFormData(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDomStorageEnabled(true);
//local offline loader
webSettings.setCacheMode( WebSettings.LOAD_DEFAULT );
projectLoaderView.loadUrl("http://google.com");
projectLoaderView.setWebViewClient(new WebViewClient());
SourceProjectActivity.this.progress.setProgress(0);
}
private class MyWebViewClient extends WebViewClient {
#Override
public void onProgressChanged(WebView view, int newProgress) {
//super.onProgressChanged(view, newProgress);
}
}
public void setValue(int progress) {
this.progress.setProgress(progress);
}
#Override
public void onBackPressed(){
if(projectLoaderView.canGoBack()){
projectLoaderView.goBack();
}else {
super.onBackPressed();
}
}
}
Here is my xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app=""
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_source_project"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mypage.mypage.SourceProjectActivity">
<WebView
android:id="#+id/sourcejailview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" >
<ProgressBar
style="#android:style/Widget.Material.Light.ProgressBar.Small"
android:layout_width="match_parent"
android:layout_x="124dp"
android:layout_y="43dp"
android:id="#+id/progressBar"
android:layout_height="wrap_content" />
</WebView>
</RelativeLayout>
WebViewClient doesn't have onProgressChanged() method. Instead of that you can use WebChromeClient and set progressbar as below:
private class MyWebViewClient extends WebViewClient {
public void onProgressChanged(WebView view, int newProgress) {
progress.setProgress(newProgress);
//Maybe you want to hide it once it reaches 100
if (newProgress == 100){
progress.setVisibility(ProgressBar.GONE);
}
}
}

My Blog App Has Been Crashed

here i have a question. I have already make my blog app. But, when i run this app, suddenly it crashed. Here my source code
package blog.app;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class MainActivity extends Activity
{
private WebView myWebView;
private WebSettings myWebSettings;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView myWebView=(WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://teknorats.blogspot.com");
WebSettings myWebSettings=myWebView.getSettings();
myWebSettings.getJavaScriptEnabled();
myWebView.setWebViewClient(new WebVewClient());
}
private static class WebVewClient extends WebViewClient {
public WebVewClient() {
}
}
public class WebAppInterface{
Context mContext;
WebAppInterface(Context c) {
mContext=c;
}
private WebAppInterface() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.addJavascriptInterface(new WebAppInterface(),"Android");
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
}
And this is the xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webview"
android:src="#drawable/tr_launcher"
>
</LinearLayout>
Please, i need your correction with that code.
If you ask where i got this code, i got this code from here http://developer.android.com/guide/webapps/webview.html
It seems that in your xml file LinearLayout tag has id webview and you are trying to get
cast LinearLayout to WebView.
So change
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webview"
android:src="#drawable/tr_launcher"
>
</LinearLayout>
to
<Webview xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webview">
</Webview>
and you has already defined myWebView as class variable so change
WebView myWebView=(WebView) findViewById(R.id.webview);
to
myWebView=(WebView) findViewById(R.id.webview);

Categories

Resources