How to set theme to ProgressDialog? - java

I would like to set theme of progressDialog. To create it, I use this code:
progressDialog = ProgressDialog.show(this, "Please Wait", "Loading dictionary file....", true, false);
I can't just write
progressDialog = new ProgressDialog(...);
progressDialog.(do_sth_with_dialog);
progressDialog.show(...)
because the show() method is static and I get compiler warning.
Is there any way to use available constants like
progressDialog.THEME_HOLO_DARK
to set the dialog theme?
I would also like to change the Dialog background and make the corners round (I don't want to change anything with the progressBar that is inside progressDialog. There is many tutorials here, but they usually describe how to create new class that extends progressDialog class.
Is there easier way to set THEME and BACKGROUND color of progressDialog?
Why I can access constants like progressDialog.THEME_HOLO_DARK if I cant use them?

ProgressDialog.show() are static methods, so you don't get a class instance of ProgressDialog that you can set properties on.
To get a ProgressDialog instance:
// create a ProgressDialog instance, with a specified theme:
ProgressDialog dialog = new ProgressDialog(mContext, ProgressDialog.THEME_HOLO_DARK);
// set indeterminate style
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// set title and message
dialog.setTitle("Please wait");
dialog.setMessage("Loading dictionary file...");
// and show it
dialog.show();
EDIT 8/2016:
Regarding the comments about deprecated themes, you may also use styles.xml and inherit from a base theme, e.g.:
<style name="MyProgressDialog" parent="Theme.AppCompat.Dialog">
</style>
the details on how to do this are already covered extensively elsewhere, start with https://developer.android.com/guide/topics/ui/themes.html.
Using themes and styles.xml is (in my opinion) a much cleaner and easier to maintain solution than hard-coding a theme when instantiating the ProgressDialog, i.e. set it once and forget it.
Then you can just do
new ProgressDialog(mContext);
and let your global theme/style provide the styling.

Sorry.. I'm working right now. Can't give full details. But here is the answer.
ProgressDialog progressDialog;
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB){
progressDialog = new ProgressDialog(new ContextThemeWrapper(context, android.R.style.Theme_Holo_Light_Dialog));
}else{
progressDialog = new ProgressDialog(context);
}
progressDialog.setMessage("Loading....");
progressDialog.show();

You cannot inflate ProgressDialog.
What you can do is while doing async task, you can show custom dialog which you can create by inheriting from Dialog class.
Also see how to set background image for progress dialog?

dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.item_dialog);

Related

How to implement dialog that help users to know the app features?

I need to Implement the dialoges given in Image to introduce attributes of App, I couldn't find the way to implement it yet.
I have tried Firebase InAppMessaging but it's automatically being displayed just after the App starts. What I need is the Message dialog should display after a button gets clicked.
the code I putted in the button.OnclickListener
FirebaseInAppMessaging.getInstance().triggerEvent("CompaignId");
Link to Firebase InAppMessaging Docs from where I get the given code
You can use BubbleShowCase to achieve your dialog.
How to use it in the simplest way:
BubbleShowCaseBuilder(this) //Activity instance
.title("foo") //Any title for the bubble view
.targetView(view) //View to point out
.show() //Display the ShowCase
And if you will read more in the library page you can find info about making a custom dialog.
You can use full-screen dialog with transparent background and show whatever feature you have to show
e.g
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_layout);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
dialog.show()
There's a lot of libraries out there, but if you want a google like showcase, you can use ShowCaseView
ShowcaseViewBuilder showcaseViewBuilder;
showcaseViewBuilder = ShowcaseViewBuilder.init(this)
.setTargetView(fab)
.setBackgroundOverlayColor(0xdd4d4d4d)
.setRingColor(0xcc8e8e8e)
.setRingWidth((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()))
.setMarkerDrawable(getResources().getDrawable(R.drawable.arrow_up), Gravity.LEFT)
.addCustomView(R.layout.description_view, Gravity.TOP)
.addCustomView(R.layout.skip_layout)
.setCustomViewMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 70, getResources().getDisplayMetrics()));

How to setTheme to dark on one Button

Guys are possible setTheme from ThemeUtils with one button ?? look at screenshot just one button 'invert' to set Light to Dark and Dark to Light ? if possible how to do it ?? pls help me
my code :
case R.id.Invert:
ThemeUtils.setTheme(this, "dark");
return true;
look this image : https://drive.google.com/file/d/0B5SpWSpauPDuSGtWREgybnB6aEk/view?usp=drivesdk
You have to call the setTheme method on the Activity before calling SetContentView
Therefore to change theme of an Activity that is already open, you would need to restart it.
For example:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(YOUR_THEME_FROM_SHARED_PREFS);
setContentView(...)
}
and
case R.id.Invert:
// Set theme in shared Prefs here
this.recreate(); // restart the activity
return true;
Yes, sure. Define theme, you want to set in style folder. And instead of your string write code R.style.YourOwnTheme

ProgressDialog spinner doesn't appear while the dialog do (no spinner at all)

I am new to android development and stuff. Working on an existing android application and tried to use progressDialogue the spinner one.
I have declared the progressdialog kinda globally. showing and dismissing them in separate methods both of which run on ui thread.
private void progressShow()
{
runOnUiThread(new Runnable() {
#Override
public void run() {
//progress_layout.setVisibility(View.VISIBLE);
progressDialog = new ProgressDialog(LoginActivity.this,R.style.Theme_IAPTheme);
progressDialog.setIndeterminate(true);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("Authenticating...");
progressDialog.show();
login_button.setEnabled(false);
register_button.setEnabled(false);
user_name_edit_text.setEnabled(false);
}
});
}
The code above is working fine but the style of the progressdialog is very dumb. When I don't mention R.style.Theme_IAPTheme the style is a good one but there is no spinner there.
How would I get some other style?(I am learning from this link:http://sourcey.com/beautiful-android-login-and-signup-screens-with-material-design/). This guy used R.style.AppTheme_Dark_Dialog which becomes red for me when I use it. :DDDD
One of the great things about android is availability of so many open source libraries. If you're not satisfied by the style of progress dialog you can use a custom one. Refer to this URL, a list of few fancy progress dialogs you might like.
Are transitions turned off in developer options on the device.
This can cause certain animations from the system to not display. Unfortunately, that includes the progress dialog spinner.

Removing ProgressDialog when user presses the back button

I have an activity that queries a server database and returns a list of results...while querying the app displays a simple progressDialog on the onCreate method like so:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//display progress dialog while querying server for values
final ProgressDialog dialog = ProgressDialog.show(this,"","Retrieving listings please wait...");
dialog.setCancelable(true);
dialog.show();
If the user clicks on an item from the list then another activity placeDetails is opened. Once done a user can press the back button to go back to the previous activity which displays the listings.
When I tested it naturally it shows the above dialog and sends the query back to the server even though the listings can be seen in the background of the progressDialog.
What I want to know is how would I prevent the database being queried again and the above progressDialog from displaying when the user presses the back button.
Do I have to go down the caching route? or is there another way?
1.) To prevent the database from being queried again you can simply cache this data in a local SQLite database as Tom Dignan mentioned.
2.) To prevent the progressDialog from displaying when the user presses the back button, simply override the onBackPressed() method of the current activity (when back is pressed) and set an Intent to the activity that preceeds the progresDialog. I believe there's even a method to do this so that you won't be starting a new instance of that activity but simply accessing a cached version.
I managed to solve this issue the missing link was I did not know how to check for dialog windows the following code helped:
//first declare the dialog so its accessible globally through out the class
public class ListPlaces extends ListActivity {
ProgressDialog dialog;
then on the onCreate first check that a dialog exists or not
if(dialog == null){
dialog = ProgressDialog.show(this,"","Retrieving listings please wait...");
//display progress dialog while querying server for values
dialog.setCancelable(true);
dialog.show();
}
And the mistake was I was using
dialog.hide();
instead of
dialog.dismiss();
Thanks for the contributions

Issue to call setMessage() on ProgressDialog

I'm having an issue creating a ProgressDialog in my onCreateDialog() method.
The code is as follows:
Dialog dialog;
switch(id){
case CONNECTING:
dialog = new ProgressDialog(this);
dialog.setMessage("Connecting").setTitle("");
return dialog;
Eclipse throws me an error setMessage wouldn't be a valid Method of the type ProgressDialog, though I expect it to be there since the documentation for API8 (which I use) says so.
AFAIK the instantiation should be possible since ProgressDialog ihnerits from Dialog right?
Can someone help me at this? It's really weird.
You need to change your code to:
Dialog dialog;
switch(id){
case CONNECTING:
dialog = new ProgressDialog(this);
((ProgressDialog)dialog).setMessage("Connecting");
dialog.setTitle("");
return dialog;
Alliteratively, you can change dialog to type ProgresssDialog if you are always returning a ProgresssDialog, but I doubt it.
The issue is that Dialog doesn't have a setMessage method. Which is the type of the variable dialog.
Edit:
This line:
dialog.setMessage("Connecting").setTitle("");
Also looks wrong since setMessage() returns void.

Categories

Resources