Android; A progressbar with a custom dialog - android

I've have a custom dialog displaying a splash screen;
mSplashDialog = new Dialog(MyActivity.this,R.layout.splash);
mSplashDialog.setContentView(R.layout.splash);
mSplashDialog.setCancelable(true);
mSplashDialog.show();
The splash layout has a ProgressBar on it;
LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/picture_splash"
ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="#+id/progressbar_Horizontal"
android:max="100"
LinearLayout
But when I try to reference to the progress bar;
progress = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
progress.setMax(100);
I've found out in the debugger that the app crashes on the second line because the object progress = null, empty zipp, nuttin :(
It seems like that the progressbar, once docked in a dialog is not accessable... :(
Somebody knows a way around this?
A ProgresDialog is not a option, because you can't customize it...
Thanks guys!

Check that you are invoking findViewById() in the correct context. For example, what you currently have is equivalent to:
progress = (ProgressBar)this.findViewById(R.id.progressbar_Horizontal);
If mSplashDialog is not part of the view hierarchy for "this", then findViewById will never find your progressBar. Perhaps you want something like:
progress = (ProgressBar)mSplashDialog.findViewById(R.id.progressbar_Horizontal);

Related

ProgressDialog showing white background dialog with progress inside it

I am trying to show a simple progress (indeterminate) to indicate that it is loading.
Here is the code I am using
ProgressDialog progressDiag = new ProgressDialog(this);
progressDiag.setIndeterminate(true);
progressDiag.show();
Where this refers to the current AppCompatActivity
However this is what I am getting
As you can see, it is displaying White dialog with progress bar at the side of it!
Why is the progress circle inside a white dialog, how can I get rid of that or at least make it as big as the progress circle (and in the middle)?
This looks like there is contents missing
Thank you
Use ProgressBar for this
<ProgressBar
android:id="#+id/pb"
android:indeterminate="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
https://developer.android.com/reference/android/widget/ProgressBar.html

Text alignment of progress dialog in Android

I am developing an Android app. In my app , I am showing progress dialog. I can show it very easily. But the problem is as in screenshot below.
As you can see above the circle is aligned to left. I want to center it. I searched solutions online. But all solutions are complicated. For example I have to create custom dialog extending dialog class. But I think it is not worth to do it. Besides, I think android has the built in easy way to do it.
This is my code to show dialog:
public void showLoginLoadingPopUp()
{
loadingDialog = new ProgressDialog(this);
loadingDialog.setTitle("Loading please wait . . .");
loadingDialog.show();
}
As you can see, the code is so simple. I also want simple code to align circle to center of dialog without customizing dialog class.
Example loadingDialog.setTextAlign(center).
But I cannot find any function to do it. What would be the easiest way to do it ?
you have used setTitle() instead of that use setMessage().
public void showLoginLoadingPopUp()
{
loadingDialog = new ProgressDialog(this);
loadingDialog.setMessage("Loading please wait . . .");
loadingDialog.show();
}
Thats it.
Progress dialog can be upgraded with custom layout, which displays required result
ProgressDialog progressDialog = ProgressDialog.show(this, null, null, true, false);
progressDialog.setContentView(R.layout.progress_layout);
And with layout XML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
Hope this helps!!!

Material Design Progress Dialog with transparent background

I'd like to put an indeterminate Progress Dialog material-compliant in my app. I found two ways to achieve it:
1- Using material-dialogs: https://github.com/afollestad/material-dialogs
2- Using the build-in dialogs of material-design-library: https://github.com/navasmdc/MaterialDesignLibrary#dialog
Using any of these solutions I get something pretty much like this: a dialog with a progressbar in it.
What I'd like to get is just the circular progress bar, without the surrounding light-grey view and without any text. A lot of apps proved us that the user knows that when something's spinning around he just needs to wait: there's no need to write it in letters. What I mean is pretty much something like this, but material.
I don't think this is such a strange question (or is it?) but I wasn't able to find any good answer online. Does anyone of you know how to achieve this?
Thank you
[Edit] I must say that in the gitHub issues of the material-dialogs library this seems to be discussed but the developer closes it fast by saying that it would mean not to follow the guidelines: https://github.com/afollestad/material-dialogs/issues/277
You can use this code,work fine in devices >= 19 (Kitkat)
progress = ProgressDialog.show(Splash.this, null, null, true);
progress.setContentView(R.layout.elemento_progress_splash);
progress.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
progress.show();
element progress splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#null"
>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/ColorTipografiaAdeudos"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Comprobando sus datos"
android:layout_below="#+id/progressBar1"
android:layout_centerHorizontal="true"
android:id="#+id/textView6"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#color/ColorFuente"
android:layout_gravity="center_horizontal" />
</RelativeLayout>
To sum up our combined with the author efforts:
The main objective was to get a dialog appearance effect (specifically background dimming) for the progress indicator of a type "material progress wheel" with the transparent background of the dialog itself.
How we've gone about it (one of the possible ways):
This library is used as the material progress wheel.
A separate layout file is created (e.g., progress_wheel.xml) containing the progress wheel layout <com.pnikosis.materialishprogress.ProgressWheel>.... If you find yourself in a situation when the wheel's dimensions do not change as per your layout settings, wrap it with a FrameLayout with wrap_content dimensions.
Inflate this layout with a layout inflater to get a view, e.g. dialogView.
Create the dialog:
Dialog progressDialog = new Dialog(context);
progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
progressDialog.setContentView(dialogView);
progressDialog.show();
Call this function on dialogView to make the dialog background transparent:
public static void clearParentsBackgrounds(View view) {
while (view != null) {
final ViewParent parent = view.getParent();
if (parent instanceof View) {
view = (View) parent;
view.setBackgroundResource(android.graphics.Color.TRANSPARENT);
} else {
view = null;
}
}
}

progressbar setvisible not working

I have a layout like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#drawable/menu_background"
>
<ProgressBar
android:id="#+id/aPBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="#android:style/Widget.ProgressBar.Inverse"/>
...
</RelativeLayout>
And in my onCreate method I do this to hide the ProgressBar at first:
LayoutInflater inflater = getLayoutInflater();
RelativeLayout layout = (RelativeLayout)inflater.inflate(R.layout.achievements_screen, null);
progressBar=(ProgressBar)layout.findViewById(R.id.aPBar);
progressBar.setVisibility(View.INVISIBLE);
But the ProgressBar is still visible all the time ... I also tried View.GONE.
When i set
android:visible="gone"
in the XML file, the ProgressBar doesnt show up, but I can't make it appear with
progressBar.setVisibility(View.Visible);
You are inflating a new view using the Layout Inflater. This is NOT the view currently on the screen.
Therefore changing it's visibility won't affect the screen UI.
Further up your Activity you must have called setContentView and this is the layout that is visible on your UI.
Therefore calling:
findViewById will return your progress bar on the screen, but calling layout.findViewById will return that layouts progress bar (correctly) but that is not the progressBar you can see on your screen.
This work for me:
rootView.findViewById(R.id.progress_bar).setVisibility(View.GONE);
Workaround for me was to hide the view in XML and then unhide/hide it at runtime when needed:
android:visibility="gone"

Understanding android dialog layouts

I'm making a simple custom dialog for my android app, displaying only a seek bar. However, the complications of this simple task are driving me nuts.
My layout for the dialog is as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<SeekBar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialogVolumeSlider"
android:layout_width="225dp"
android:layout_height="wrap_content"/>
</LinearLayout>
The dialog is created in code:
Dialog d = new Dialog(this);
d.setContentView(R.layout.custom_dialog);
return d;
Instead of a simple box wrapping the seekbar, I get this phantom space coming from somewhere:
What's the issue here? I've tried modifying
d.getWindow().getAttributes().height
but this creates additional problems as well.
Thanks for any help!!
EDIT: Stranger things happen when I assigned a fixed "50dp" to my LinearLayout's layout_height:
By default a Dialog will leave space for a title even if you don't set one (with d.setTitle()) .
You can either set a title to fill the space or request that the Dialog not have a title.
Here is an example of how to request the no title setting.
Dialog d = new Dialog(this);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.custom_dialog);
With no title, your SeekBar will appear as you expect.
Try putting a fixed Height on your parent linear layout. Something like:
android:layout_height="50px"

Categories

Resources