How to make ProgressDialog Transparent in android - 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();

Related

How can I change default dialog button text color?

How can I change the default text and background color of Dialog buttons (setPositiveButton, setNeutralButton)?
public void onBackPressed(){
if(webView.canGoBack()) {
webView.goBack();
}else{
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.create();
dialog.setTitle("Confirmation ...");
dialog.setMessage("Are you sure ! \nYou want to exit from app ?");
dialog.setCancelable(false);
dialog.setPositiveButton("Yes", (dialogInterface, which) -> finish());
dialog.setNeutralButton("Cancel", MainActivity::onClick);
dialog.show();
}
}
If your AppTheme is inherited from Theme.AppCompat:
<style name="AlertDialogTheme" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="buttonBarPositiveButtonStyle">#style/PositiveButtonStyle</item>
<item name="buttonBarNeutralButtonStyle">#style/NeutralButtonStyle</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#FFFFFF</item>
<item name="android:background">#F44336</item>
<item name="android:width">90dp</item>
<item name="android:padding">0px</item>
</style>
<style name="NeutralButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#F44336</item>
<item name="android:background">#FFEB3B</item>
<item name="android:width">90dp</item>
</style>
Use your AlertDialogTheme in your AppTheme
<item name="alertDialogTheme">#style/AlertDialogTheme</item>

Why is My Android Alert dialog BLACK?

Can you help my figure out why is my alert dialog BLACK?!
Recently i changed my app theme to support material design, but my alert dialog got black!
Here is my create dialog Code:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(TestActivity.this);
alertDialog.setCancelable(true);
alertDialog.setTitle("sample");
alertDialog.setItems(new String[] { "a", "b" }, new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alertDialog.show();
and its my main style and dialog style
<style name="MaterialTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:alertDialogStyle">#style/AppDialog</item>
<item name="android:alertDialogTheme">#style/AppDialog</item>
<item name="android:textColor">#color/black</item>
<item name="android:textColorPrimary">#color/black</item>
<item name="android:dialogTheme">#style/AppDialog</item>
<item name="colorPrimaryDark">#color/myPrimaryDarkColor</item>
<item name="android:textColorHint">#color/gray_1</item>
<item name="colorAccent">#color/myAccentColor</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:windowBackground">#color/black</item>
</style>
<style name="AppDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#FFC107</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:background">#4CAF50</item>
</style>
You don't set theme for AlertDialog, for using theme, change code to:
ContextThemeWrapper ctw = new ContextThemeWrapper(TestActivity.this, R.style.AppDialog);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ctw);
you must use a light theme with your alertdialog builder such as the THEME_HOLO_LIGHT.
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this,AlertDialog.THEME_HOLO_LIGHT);

Why is the text selection tool is half shown and is not clickable

I have an AppCompatActivity which contains android.app.Fragment. In fragment I have a button on the toolbar which fires the method showDialog():
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_add_ingredient) {
showDialog();
return true;
}
return super.onOptionsItemSelected(item);
}
private void showDialog() {
// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// 2. Chain together various setter methods to set the dialog
// characteristics
builder.setTitle(R.string.dialog_ingredient_add_title);
builder.setView(mActivityMain.getLayoutInflater().inflate(
R.layout.dialog_shopping_ingredient_add, null));
builder.setPositiveButton(R.string.dialog_ingredient_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
builder.setNegativeButton(R.string.dialog_ingredient_cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
// 3. Get the AlertDialog from create()
dialog = builder.create();
dialog.show();
}
As it can be seen from the code, a android.support.v7.app.AlertDialog appears.
Picture 1. AlertDialog shown.
Then I select some text.
Picture 2. Text selected.
And somehow text selection tool shows only half of it and is unclickable.
My styles.xml file is below.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base" />
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- colorPrimary is used, for instance, for the default ActionBar (but not Toolbar) background. We specify the same color for the toolbar background in toolbar.xml.. -->
<item name="colorPrimary">#color/color_primary</item>
<!-- colorPrimaryDark is used for the status bar (with the battery, clock, etc). -->
<item name="colorPrimaryDark">#color/color_primary_dark</item>
<!-- colorAccent is used as the default value for colorControlActivated which is used to tint widgets. -->
<item name="colorAccent">#color/color_accent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:itemTextAppearance">#style/MenuTextApearance</item>
<item name="colorControlNormal">#000000</item>
<item name="colorControlActivated">#color/color_highlight_text</item>
<item name="colorControlHighlight">#color/color_highlight_text</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:textColorHighlight">#color/color_highlight_text</item>
<item name="actionModeBackground">#drawable/myapp_action_mode_background</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<style name="MenuTextApearance" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#000000</item>
</style>
<style name="ActionBarThemeOverlay" parent="">
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="colorControlNormal">#FFFFFF</item>
<item name="colorControlHighlight">#00000000</item>
</style>
<style name="HeaderBar">
<item name="android:background">?colorPrimary</item>
</style>
<style name="HeaderBarTransparent">
<item name="android:background">#color/color_primary_transparent</item>
</style>
<style name="ActionBarPopupThemeOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="android:background">#00000000</item>
<item name="android:textColor">#FFFFFF</item>
</style>
Question:
How can I make the text selection tool fully visible and clickable?

Activity theme appears different than other Activities of the application

Hello I am working on an android application. I am showing the ProgressDialog when perform the network operation in an application. But theme of ProgressDialog appears different in different activities.
<activity
android:name="teemwurk.android.ClockActivity"
android:label="#string/title_activity_clock"
android:screenOrientation="portrait"
android:theme="#style/CustomTheme" >
</activity>
customtheme.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground </item>
<item name="android:windowTitleSize">60dp</item>
</style>
<style name="WindowTitleBackground">
<item name="android:padding">0px</item>
<item name="android:background">#F3F8FB</item>
</style>
</resources>
ClockActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // requesting to set
// the custom title
// bar
setContentView(R.layout.activity_clock);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
// set the back button on click listener
((TextView)findViewById(R.id.backTextView)).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
}
TeemWurkAsyncTask.java
public class TeemWurkAsyncTask extends AsyncTask<String, Void, String> {
private ProgressDialog mProgressDialog;
private Context mContext;
private TaskCompleteListener taskCompleteListener;
private int method;
private String TAG = "TeemWurkAsyncTask";
public TeemWurkAsyncTask(TaskCompleteListener taskCompleteListener, int method, Context mContext) {
this.taskCompleteListener = taskCompleteListener;
this.method = method;
this.mContext = mContext;
}
#Override
protected void onPreExecute() {
// display the progress dialog
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setTitle(mContext.getString(R.string.app_name));
mProgressDialog.setMessage(mContext.getString(R.string.please_wait));
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setCancelable(false);
mProgressDialog.setIndeterminate(true);
mProgressDialog.show();
}
But I want it should appear like below this ProgressDialog
Thanks in advance.
Try this .You should change this
<style name="CustomTheme" parent="android:Theme">
........
</style>
to
<style name="CustomTheme" parent="#android:Theme.Holo.Light">
........
</style>
Try this..
Change this..
<style name="CustomTheme" parent="android:Theme">
to
<style name="CustomTheme" parent="#style/AppTheme">
EDIT
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomTheme" parent="#style/AppTheme">
<item name="newStyle">#style/CustomThemeStyle</item>
</style>
<style name="CustomThemeStyle" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground </item>
<item name="android:windowTitleSize">60dp</item>
<item name="android:windowActionBar">false</item>
</style>
<style name="WindowTitleBackground">
<item name="android:padding">0px</item>
<item name="android:background">#F3F8FB</item>
</style>
</resources>
EDIT
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="newStyle" format="reference" />
</resources>

Custom Progress Dialog Animation

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

Categories

Resources