I need to show a ProgressDialog when my WebView is loading, so that the user cannot see the page loading in the background. I can only get my dialog to show up as a little box, I would like the dialog to fill up all the space below the action bar.
How can I achieve this? I have used the method progressDialog.setProgressStyle() but without any luck.
If there are any other better ways of achieving this, please let me know. My ultimate aim is for the app to behave like the Facebook (pre-native) app, where the 'Loading' indicator was visible until the page had finished loading.
I resolved this issue myself. I have used a different method to achieve the same effect. I am not sure whether or not it is best practice, but my webview layout now looks like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- WebView progress -->
<LinearLayout
android:id="#+id/webProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="gone" >
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp" />
<TextView
android:id="#+id/login_status_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Loading"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="visible" />
</LinearLayout>
And to show and hide the progress I use:
View webProgress = findViewById(R.id.webProgress);
...
public void showWVProgress() {
webProgress.setVisibility(View.VISIBLE);
isWVProgressShowing = true;
}
public void hideWVProgress() {
webProgress.setVisibility(View.GONE);
isWVProgressShowing = false;
}
Related
I want to make a button which has an indeterminate progress bar around it's outside, as we can see here.
Based upon the available widgets, I cannot see how to make a circular button with this progress bar on it's outside.
At this point, I have my floating action button:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="?android:attr/actionModeWebSearchDrawable" />
With no progress bar!
I found this example - but cannot get it to load correctly into my project.
Is there a 'native' simple way to achieve this design?
Update
Following help, now I have something like this:
Note the right hand is the suggested answer. Left hand is the style of button I am aiming for.
My code is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.progressindicator.CircularProgressIndicator
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progress="50"
app:indicatorColor="#color/colorAccent"
app:trackColor="#color/colorPrimary"
app:trackThickness="2dp"
/>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="?attr/colorSecondary"
app:cardCornerRadius="24dp"
android:layout_gravity="center"
app:cardPreventCornerOverlap="true">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="?android:attr/actionModeWebSearchDrawable"/>
</androidx.cardview.widget.CardView>
</FrameLayout>
</LinearLayout>
Basically the left hand button is slightly larger with slightly smaller search image -- how can I edge closer to this? I have tried playing but can't quite get the sizing right. I thought adding padding would help but doesn't seem to make a difference. I wonder if there is a way to combine your solution with my floating action button - to perhaps get the best of both worlds more easily?
Instead of Floating button maybe you can try it this way with Frame Layout and CardView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.progressindicator.CircularProgressIndicator
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progress="50"
app:indicatorColor="#color/colorAccent"
app:trackColor="#color/colorPrimary"
app:trackThickness="2dp"
/>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="25dp"
android:layout_gravity="center"
app:cardPreventCornerOverlap="true">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="#drawable/app_top_logo"/>
</androidx.cardview.widget.CardView>
</FrameLayout>
</LinearLayout>
i have a basic layout which contains some views. When there is a network connection a RecyclerView is shown. When the user swipes to refresh and there is no connection a button and a textview, which are inside the basic layout invisible at first place, become visible. The problem is that the button is not clickable in devices with Android version < Lollilop.
basic_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listSurveysRlt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.rey.material.widget.TextView
android:id="#+id/codeDescTtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/code_dest_txv_padding_bottom"
android:visibility="gone"
android:gravity="center"
android:layout_above="#+id/sRetryBtn"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textSize="#dimen/code_dest_txv_text_size"
android:textColor="#android:color/black"
android:textStyle="bold" />
<com.rey.material.widget.Button
android:id="#+id/sRetryBtn"
android:layout_width="#dimen/action_btn_width"
android:layout_height="#dimen/action_btn_height"
android:text="#string/retry"
android:textColor="#android:color/white"
android:background="#drawable/ripple_drawable"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="gone" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeRefreshLlt"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/completedSurveysRcV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/surveys_rcv_margin_top" />
</android.support.v4.widget.SwipeRefreshLayout>
<ImageView
android:id="#+id/noSurveysImv"
android:layout_width="#dimen/no_surveys_imv_width"
android:layout_height="#dimen/no_surveys_imv_height"
android:src="#drawable/no_surveys"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/no_surveys_imv_margin_top"
android:visibility="gone"
android:contentDescription="#string/ongoing" />
<com.rey.material.widget.TextView
android:id="#+id/noSurveysTxv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/noSurveysImv"
android:text="#string/no_completed"
android:textSize="#dimen/no_surveys_txv_text_size"
android:textColor="#color/no_surveys_txv_color"
android:visibility="gone"
android:layout_centerHorizontal="true" />
</RelativeLayout>
the method which transforms the corrensponding views from visible to invisible and vice versa:
private void onErrorBackgroundView(int code) {
listSurveysRlt.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.view_color));
completedSurveysRcV.setVisibility(View.GONE); //RecyclerView
codeDescTtv.setVisibility(View.VISIBLE); //TextView
retryBtn.setVisibility(View.VISIBLE); //not clickable button
codeDescTtv.setText(getResources().getString(inputValidationCodes.get(code)));
}
After some digging i found out the reason behind this strange behavior of the framework. The culprit was the SwipeRefreshLayout that blocked ui clicks ,so by setting the visibility of this layout to gone every time the user swipes the screen and restore the visibility when connection is available solved the issue. If anyone knows why this was happening in versions < Lollipop, it would be much helpful.
I'm writing an application and have come across a bit of an issue.
When working with a layout file, I have a 2 RelativeLayouts inside of a ViewFlipper.
The idea is that this page in particular is a welcome screen. The first RelativeLayout "welcomes" you to the app, and upon pushing a button, the user is led to the second RelativeLayout. In this layout there is a search bar that will allow the user to search for a certain criteria (specific to the app, not important) then display the results in a ListView.
Everything works correctly, but displaying the ListView seems to have some problems. The adapter is set properly, and I tested the method on another ListView in a test layout, and it worked fine. However something seems wrong with the ListView in the RelativeLayout. Here is the layout code
activity_welcome.xml
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/welcomeFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true"
android:background="#color/white"
tools:context="com.jacemcpherson.announcer.WelcomeActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:padding="40dp">
...
<!-- This code irrelevant, all's well :) -->
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="#color/white"
android:padding="40dp">
<TextView
android:id="#+id/textFirstThingsFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textYouNeedToSearch"
android:layout_centerHorizontal="true"
android:text="#string/first_things_first"
android:textColor="#color/app_color"
android:textSize="32sp" />
<TextView
android:id="#+id/textYouNeedToSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center"
android:text="#string/you_need_to_search_for_your_school"
android:textColor="#color/black"
android:textSize="18sp" />
<EditText
android:id="#+id/schoolSearchEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textYouNeedToSearch"
android:hint="#string/search_hint" />
<ProgressBar
android:id="#+id/searchListProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/schoolSearchEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:visibility="gone" />
<!-- This is the problem area -->
<ListView
android:id="#+id/searchResultsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/schoolSearchEditText" />
</RelativeLayout>
</ViewFlipper>
I'm setting the adapter works like normal, but just in case I missed something, here's the line of code for that...
mListView.setAdapter(new ArrayAdapter<String>(
mContext,
android.R.layout.simple_list_item_1,
result // this is the array of results to be displayed in the list.
));
Thank you for your help, if I've missed something that in some way makes this unanswerable without further information, please let me know.
Change the layout_height from wrap_content to either match_parent or fill_parent.
This is explained very well by this answer.
I am developing an android app and came across a trivial problem that i could not figure out.
I am trying to show progress circle after user clicks on search button. But some how I am not able to create progress bar with code I have written so far.
Code is as below..
In my fragment class below is code for search button click...
//create a progress dialog circle.
spinner = (ProgressBar) searchByDoctor.findViewById(R.id.progressBar1);
spinner.setVisibility(View.VISIBLE);
spinner.setIndeterminate(true);
List<DocInfoTO> docList = doctorService.findDocBySearchCriteria(docSearchInputTO);
if(docList != null && docList.size() > 0)
{
//stop the progress cirlce as soon as we get the results.
spinner.setVisibility(View.GONE);
spinner.setIndeterminate(false);
List<SearchResultDoctorRowItem> rowItems = new ArrayList<SearchResultDoctorRowItem>();
for(DocInfoTO doc : docList)
{
rowItems.add(YourDocUtil.setDoctorRowItemDto(doc));
}
The xml is like this,
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/android">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/enter_doc_name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="center_horizontal"
android:paddingTop="200dp"/>
<EditText
android:id="#+id/editText1"
android:layout_width="238dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="#string/doctor_Name" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<LinearLayout
android:id="#+id/footerSearch"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/black_overlay"
android:orientation="horizontal"
>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/searchDoc"
/>
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"/>
</FrameLayout>
You code is fine. The reason you are not able to see the progress bar because it is going from spinner.setVisibility(View.VISIBLE) state to spinner.setVisibility(View.GONE) too quickly. In short you progress bar is appearing and disappearing too quickly for you to notice it.
If this code doctorService.findDocBySearchCriteria(docSearchInputTO) took longer to execute you would be able to see your progress bar. `
Make sure you have not called spinner.setVisibility(View.GONE) or spinner.setVisibility(View.Invisible) somewhere above the code you have written. It will cause the spinner to stop appearing.
I have a small animation in my app, that in the end of it changes the location parameters of a ListView i.e. it comes a bit lower than when it started (It starts as full screen and after a button press, its sliding down a little to reveal something beneath it, on the top of the screen). By pressing on the list I can see that its parameters realy changed and its location really changed. Now, if the SlidingDrawer is getting opened at that point, the layout gets rearranged and the list is back to full screen. Why is that?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.softtechnics.mobuynet"
android:id="#+id/coupon_list_layout"
style="#style/FillParent"
android:orientation="vertical" >
<include
android:id="#+id/filter_tab"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_below="#+id/action_bar"
layout="#layout/filter" />
<com.softtechnics.mobuynet.gui.components.ListArr
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/footer"
android:layout_below="#+id/action_bar">
</com.softtechnics.mobuynet.gui.components.ListArr>
<com.softtechnics.mobuynet.gui.components.ActionBar
android:id="#+id/action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ProgressBar
android:id="#+id/progress"
style="#style/WrapContent"
android:layout_centerInParent="true"
android:visibility="gone" />
<com.softtechnics.mobuynet.gui.components.Footer
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="#+id/textView1" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="113dp"
android:layout_alignParentBottom="true"
android:visibility="invisible" />
Footer is my SlidingDrawer.
Thanks!
You have to change listview properties when the animation ends. Also you should remember actual state of this view and update it in onResume method.