My app has 5 tabs and starts with tab 1 selected. Another tabs contains a webview that loads an html file and takes some seconds to display it. Is there any method to improve webview html file loading? For eg tab 3, webview does not start loading until tab is pressed, how to start loading content just when app starts and don't have to wait user tab selection?
main activity onCreate,
addTab(tab1name, R.drawable.tab_home, tab1.class);
addTab(tab2name, R.drawable.tab_search, webPush2.class);
addTab(tab3name, R.drawable.tab_home, webPush3.class);
addTab(tab4name, R.drawable.tab_search, webPush4.class);
addTab(tab5name, R.drawable.tab_home, webPush5.class);
webPush3 onCreate,
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
browse3 = (WebView) findViewById(R.id.webview1);
browse3.getSettings().setJavaScriptEnabled(true);
browse3.loadUrl("file:///data/data/" + PACKAGE_NAME + view3 + ".html");
Instead of using tabs, you can simply create a WebView with visibility of GONE. That will keep it so that it's not shown, and you can start it up loading. If you still want several screens switched based on tabs, you would just setVisibility to VISIBLE on the one one want to show, and set the others to GONE.
Related
I have a problem with showing simple google.com in my WebView.
Tried this on few emulators and 2 phones, all the same, something is wrong with my code.
1. Issue
First screen shows normally google's asking user to accept their legal stuff (1st image).
After accepting it moves to google's main page. But only lower part (Country, settings, adds, about etc.) is shown (2nd image). There is no Google logo, no search bar and buttons and no stuff from the upper display (like GMAIL, GRAPHICS, ACCOUNT and so on).
1ST SCREEN OF GOOGLE.COM
INCORRECTLY SHOWN GOOGLE PAGE
2. Code
I added permission in Manifest.
Trying to solve the issue I stackoverflowed below two lines and added to Manifest, but to no avail:
android:hardwareAccelerated="true"
android:usesCleartextTraffic="true"
**
3. My java code is below:**
(each of the settings I tried to comment out and then one by one uncomment, but still no result).
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.loadUrl("http://www.google.com");
}
}
Could someone please check this is tell me what I've done wrong here?
Stupid thing, should not have done this late into the night.
The problem was only with layout, rest of the page was out of screen.
Needed only to match the WebView to constraints.
I am creating a very simple WebView app with a few useful links and I want the initial focus to be on the app bar with easy access to the menu. This works if I add focusable attributes to the layout in main.xml
android:focusable="true"
android:focusableInTouchMode="true"
However I'm unable to navigate away from the app bar to the WebView content below unless I add requestFocus to the menu actions:
case R.id.url:
webView.loadUrl("https://example.com");
webView.requestFocus();
Then I can navigate down to the WebView content below, but as soon as I return to the app bar navigation is lost again. How can I freely navigate away from the app bar?
So I added the following code to main.xml and it solves my issue
android:nextFocusDown="#+id/webview"
I am new to Android Espresso library. Trying to test click on RecyclerView item inside the ViewPager. I've searched the Internet but found nothing about ViewPager. So my question is: how to access RecyclerView inside a ViewPager using Espresso to perform click?
Let's suppose you want to tap on buttonClick, which is the id of a button inside your RecyclerView.
I use this code:
onView(allOf(withId(R.id.buttonToClick), isCompletelyDisplayed()))
.perform(click());
This gets the view with this id which is currently displayed and performs a click on it.
Hope this helps.
P.S.: Also, on espresso-contrib there are RecyclerViewActions that maybe you can use: actionOnHolderItem, actionOnItem and actionOnItemAtPosition. You can do something like:
onView(withId(R.id.recyclerView))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
With Android 5, Google supports multiple activities in the recents screen for a single application.
I managed to implement multiple activities in the recents screen with this official doc.
How can I change the title of the activity? Switching to recents screen always shows my app name as title.
Activity.setTitle("title");
changes the title on the toolbar, but I want it to change in the recents screen, just like Google does in Google Chrome App.
I need to change the title programatically.
In your activity you can use new method:
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.secondary_layout);
setTaskDescription(new ActivityManager.TaskDescription("Activity 2"));
}
setTaskDescription sets information about activity in recents task list. In this example only title.
How can I do to load some images in a webview and save them in cache. I need this because when the user turn the page and need to view the second page the second webview can use the img stored in cache by the 1st webview that has loaded them in background.
That's the only configuration that I do on my 2 webview
webViewImageCache = (WebView)v.findViewById(R.id.webViewImageCache);
webview = (WebView)v.findViewById(R.id.webView);
//Caching
webViewImageCache.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);