Custom Progress Dialog Animation - android

I am working on Custom Progress Dialog. I've set its style like done in this SO question Positionning the spinning wheel in a custom progress dialog My progress dialog is showing no animation at all. When I changed the background to black then it was only showing a black box. I want my progress dialog to animate.
In activity I am doing something like this
public MyProgressDialog(Context context) {
super(context, R.style.NewDialog);
}
and the NewDialog is as:
<style name="NewDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTitleStyle">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:width">50dip</item>
<item name="android:height">50dip</item>
<item name="android:background">#android:color/transparent</item>
</style>
Any help is appreciated in advance

import android.app.ProgressDialog;
import android.content.Context;
import android.view.animation.Animation;
public class MyProgressDialog extends ProgressDialog {
public MyProgressDialog(Context context) {
super(context,R.style.NewDialog);
// TODO Auto-generated constructor stub
}
}
//RESOURCE STYLE FILE res->values->mydialog.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NewDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTitleStyle">#null</item>
<item name="android:colorBackground">#ffffff</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:width">600dip</item>
<item name="android:height">100dip</item>
<item name="android:textColor">#FF0000</item>
</style>
</resources>
//AND USE THIS CODE ANYWHERE IN YOUR APPLICATION TO GET CUSTOM PROGRESS DIALOG
MyProgressDialog pd = new MyProgressDialog(YouActivity.this);
pd.setMessage("Loading. Please wait...");
pd.show();
Well there isn't any difference in your code and mine as I have run your code just to test whether you are experiencing any problem or not but still I am posting for you so that you can sought out the problem.
Thanks :)

public class TransparentProgressDialog extends Dialog {
private ImageView iv;
public TransparentProgressDialog(Context context, int resourceIdOfImage) {
super(context, R.style.TransparentProgressDialog);
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER_HORIZONTAL;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(false);
setOnCancelListener(null);
resourceIdOfImage = R.drawable.loading_spinner_icon;
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
iv = new ImageView(context);
iv.setImageResource(resourceIdOfImage);
layout.addView(iv, params);
addContentView(layout, params);
}
}
You will get complete example with animation HERE

Related

How to make ProgressDialog Transparent in android

I want to make ProgressDialog Transparent but I never became Transparent It became Black background in ProgressDialog.How can I do that Kindly help
here is my code for ProgressDialog:-
private class LoginAttempt extends AsyncTask<String, Void, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity(), R.style.MyTheme);
pDialog.setCancelable(false);
pDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
pDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
pDialog.show();
}
here is my style.xml
<style name="MyTheme" parent="android:Theme.Holo.Dialog">
<item name="android:alertDialogStyle">#style/CustomAlertDialogStyle</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textStyle">normal</item>
<item name="android:textSize">12sp</item>
</style>
and also
<style name="CustomAlertDialogStyle">
<item name="android:bottomBright">#color/transparent</item>
<item name="android:bottomDark">#color/transparent</item>
<item name="android:bottomMedium">#color/transparent</item>
<item name="android:centerBright">#color/transparent</item>
<item name="android:centerDark">#color/transparent</item>
<item name="android:centerMedium">#color/transparent</item>
<item name="android:fullBright">#color/transparent</item>
<item name="android:fullDark">#color/transparent</item>
<item name="android:topBright">#color/transparent</item>
<item name="android:topDark">#color/transparent</item>
</style>
and here is my result:-
enter image description here
This works for me (Assuming I am in MainActivity) :
ProgressDialog pDialog = new ProgressDialog(MainActivity.this, R.style.AppTheme);
pDialog.setCancelable(false);
pDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
pDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
pDialog.show();
OR, if I just do
ProgressDialog pDialog = new ProgressDialog(MainActivity.this);
i.e. without supplying any theme, it works.
So turns out there's a problem in the theme that you are supplying. Try once without supplying the theme.
If you are taking <item name="android:windowBackground">#color/transparent</item> you have to define color in your color.xml for full transparency. like this:
<color name="transparent">#00FFFFFF</color>
Look here for reference:Transparent ARGB hex value
First, define your object:
private static ProgressDialog mProgressDialog;
Then create the method to run your progress dialog that includes the transparent background as below:
public static void showSimpleProgressDialog(Context context, String title, String msg, boolean isCancelable) {
try {
if (mProgressDialog == null) {
mProgressDialog = ProgressDialog.show(context, title, msg);
mProgressDialog.setCancelable(isCancelable);
mProgressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
if (!mProgressDialog.isShowing()) {
mProgressDialog.show();
}
} catch (IllegalArgumentException ie) {
ie.printStackTrace();
} catch (RuntimeException re) {
re.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
You can then call this method from your activity as:
showSimpleProgressDialog(this, "Your Title", "Your Message", false);
Use this in style file
<style name="CustomAlertDialogStyle">
<item name="android:bottomBright">#color/transparent</item>
<item name="android:bottomDark">#color/transparent</item>
<item name="android:bottomMedium">#color/transparent</item>
<item name="android:centerBright">#color/transparent</item>
<item name="android:centerDark">#color/transparent</item>
<item name="android:centerMedium">#color/transparent</item>
<item name="android:fullBright">#color/transparent</item>
<item name="android:fullDark">#color/transparent</item>
<item name="android:topBright">#color/transparent</item>
<item name="android:topDark">#color/transparent</item>
</style>
<style name="MyTheme" parent="android:Theme.Holo.Dialog">
<item name="android:alertDialogStyle">#style/CustomAlertDialogStyle</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:indeterminateTint">#color/colorPrimary</item>
</style>
and this for calling progress dialog :
ProgressDialog progressDialog = new ProgressDialog(context,R.style.MyTheme);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
progressDialog.setMessage("");
progressDialog.show();

how to remove top strip in dialog box

I open the activity in dialog box.how to remove top strip.
my themes code:
<style name="My_search_dailog" parent="Base.V7.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowBackground">#android:color/darker_gray</item>
</style>
out put:
please help me
Use LayoutInflater for your custome dialog view.
AlertDialog.Builder builder = new AlertDialog.Builder(context);
final LayoutInflater inflater = activity.getLayoutInflater();
final View view = inflater.inflate(R.layout.caution_dialog, null);
builder.setView(view);
override +ve button and -ve button
AlertDialog alert = builder.create();
alert.show();
Update your style
<style name="My_search_dailog" parent="Base.V7.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
I faced the same problem and solved it by adding "requestWindowFeature" attribute in Java file where i am showing this dialog.
Dialog dialog = new Dialog();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.show();

How to change the theme color of default fragment dialog

I have shown a dialog fragment. I have done it, but I want to change background (Theme) color grey to white.
My dialog code:
public class TestDialog extends DialogFragment {
public static TestDialog newInstance() {
return new TestDialog();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialog);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return container;
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialog);
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dailog_fragment, null))
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
TestDialog.this.getDialog().cancel();
}
});
return builder.create();
}
}
use this
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.MyDialog);
and then make the custom MyDialog style.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#color/orange_transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTitleStyle">#null</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:gravity">center</item>
</style>
</resources>
note that it should be in style.xml.
In your manifest file, the activity definition of the dialog activity, add the android:theme attribute as follows.
<activity
android:name=".YourActivityName"
android:theme="#styles/style"
/>
I Got The Solution:
I am using below style theme for set the white background color.
<style name="MyFragment">
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTitleStyle">#null</item>
<item name="android:colorBackground">#android:color/white</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
We can also use Holo Theme
AlertDialog.Builder builder = new AlertDialog.Builder(ProfileEditActionBar.this, AlertDialog.THEME_HOLO_LIGHT);

Title of the dialog is too high

How can I reduce the height of the green title?
Activity:
final Dialog dialog = new Dialog(EditorActivity.this, R.style.dialog);
dialog.setContentView(R.layout.preference_timerange);
dialog.setTitle(getString(R.string.zmien_czas_wyprawy));
Styles.xml
<style name="dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/dialog_title_style</item>
<item name="android:windowBackground">#color/dialog_background</item>
<item name="android:textColor">#color/dialog_text</item>
</style>
<style name="dialog_title_style" parent="android:TextAppearance.WindowTitle">
<item name="android:textSize">16dp</item>
<item name="android:background">#color/dialog_title_background</item>
<item name="android:textColor">#color/dialog_title_text</item>
</style>
I don't know how to change the height of the Dialog's title, but you can remove the whole title and create a smaller one in your layout preference_timerange.xml:
final Dialog dialog = new Dialog(EditorActivity.this, R.style.dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.preference_timerange);
// Set R.string.zmien_czas_wyprawy as the title in your layout now

How to remove white border in dialog?

I read many topics, but I didn't find answer of my problem. I'm trying to use android.R.style.Theme_Translucent_NoTitleBar or xml styles with
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#color/transparent_white</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowNoTitle">true</item>
</style>
Even I have added
dialog.getWindow().setBackgroundDrawableResource(R.drawable.pixel);
where pixel is transparent drawable, but with no luck. I always have white border.
My code is below:
Dialog dialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar);
dialog.getWindow().setBackgroundDrawableResource(R.drawable.pixel);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
ListView modeList = new ListView(this);
String[] stringArray = new String[] { "aaa", "bbb" };
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1,
stringArray);
modeList.setAdapter(modeAdapter);
builder.setView(modeList);
dialog = builder.create();
Regards,
Swierzy
The white border of a dialog is a 9patch image
and your background picture has to be an 9patch picture.
http://developer.android.com/guide/developing/tools/draw9patch.html
You can draw it yourself and make any border you like there.
you create your dialog like that
public AboutDialog(Context context) {
super(context,R.style.Theme_Dialog);
.......
and your style e.g.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
</style>
<style name="Theme.Dialog" parent="Theme">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/bg</item> <------- your 9patch background picture
</style>
hope this helps abit

Categories

Resources