Style for android ProgressDialog - android

I'm trying to customize ProgressDialog style to have something like that:
What I have:
I know how to change spinner style and color, but what I didn't understand that is: how to make rounded-corners, I'm trying to use android:radius attribute, but nothing changes, and I don't know how to decrease padding. Maybe I can do it programmatically?
<style name="TransparentProgressDialog" 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">#dimen/_14sdp</item>
</style>
<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>

try the below Code it works for me:
Put this XML file in drawable folder (dialog_progress_background.xml)
<corners android:radius="10dp" />
<solid android:color="#80000000" />
<padding
android:bottom="40dp"
android:left="40dp"
android:right="40dp"
android:top="40dp" />
Dailog layout (R.layout.dialog_spinner.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/progressBar"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Loading..."
android:textColor="#FFFFFF" />
</RelativeLayout>
// Class for create custom Progress Dialog
public class ProgressBuilder {
private Context context;
private Dialog dialog;
public ProgressBuilder(Context context) {
this.context = context;
}
public void showProgressDialog() {
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(
context.getResources().getDrawable(
R.drawable.dialog_progress_background));
dialog.setContentView(R.layout.dialog_spinner);
dialog.setCancelable(false);
dialog.show();
}
public TextView getTextView()
{
return (TextView)dialog.findViewById(R.id.textView1);
}
public Dialog getDialog()
{
return dialog;
}
public void dismissProgressDialog() {
dialog.dismiss();
}
}
And call showProgressDialog() method to show Progress Dialog
ProgressBuilder dialog=new ProgressBuilder(MainActivity.this);
dialog.showProgressDialog()
//to dismiss the progress dialog
dialog.dismissProgressDialog()

Related

how to change the button text color on AlertDialog globally using style?

on android O when i do this :
<style name="MyTheme" parent="#android:style/Theme.Material.Light.NoActionBar">
<item name="android:textColor">#ff0000</item>
</style>
The text button color of my alertdialog change, but this not work under lollipop. Worse on lollipop it's change the color of the title of the alertdialog instead.
How from kitkat to android O I can globally change the font color of the button of all my alertdialog ?
With the MaterialComponents theme and the MaterialAlertDialogBuilder you can define globally the style using the materialAlertDialogTheme attribute in your app theme.
Something like:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="materialAlertDialogTheme">#style/My_MaterialAlertDialog</item>
</style>
Then you can define a custom style:
<style name="My_MaterialAlertDialog" parent="#style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<!-- Style for positive button -->
<item name="buttonBarPositiveButtonStyle">#style/PositiveButtonStyle</item>
<!-- Style for negative button -->
<item name="buttonBarNegativeButtonStyle">#style/NegativeButtonStyle</item>
<!-- Style for neutral button -->
<item name="buttonBarNeutralButtonStyle">#style/NeutralButtonStyle</item>
</style>
with the button style defined by:
<style name="PositiveButtonStyle" parent="#style/Widget.MaterialComponents.Button">
<item name="android:textColor">#FFFFFF</item>
<item name="backgroundTint">#color/primaryDarkColor</item>
</style>
<style name="NegativeButtonStyle" parent="#style/Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#color/primaryDarkColor</item>
</style>
<style name="NueutralButtonStyle" parent="#style/Widget.MaterialComponents.Button.TextButton.Dialog">
....
</style>
With the version 1.1.0 of the library you can also simply override the default color using the materialThemeOverlay in the custom style:
<style name="My_MaterialAlertDialog" parent="#style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="materialThemeOverlay">#style/DialogButtonOverlay</item>
</style>
<style name="DialogButtonOverlay">
<item name="colorPrimary">#color/...</item>
</style>
You need to write a theme for AlertDialog and set it to AppTheme. It will change you alet dialog theme globally.
<style name="AppAlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="buttonBarNegativeButtonStyle">#style/NegativeButtonStyle</item>
<item name="buttonBarPositiveButtonStyle">#style/PositiveButtonStyle</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#color/colorPrimaryText</item>
<item name="android:backgroundTint">#android:color/transparent</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#color/colorPrimaryText</item>
<item name="android:backgroundTint">#android:color/transparent</item>
</style>
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
...
<item name="alertDialogTheme">#style/AppAlertDialog</item>
</style>
Create a Java Class for your custom alert dialog
public class Dialog {
private static final int resId = R.layout.dialog_dialog;
private AlertDialog alertDialog;
/**
* Custom Dialog
*
* #param context
* #param titleText
* #param message
* #param positiveText
* #param negativeText
* #param type
* #param dialogListener
*/
public Dialog(final Context context,
String titleText,
String message,
String positiveText,
String negativeText,
Type type,
final DialogListener dialogListener) {
TextView labelTitle, labelMessage, buttonPositive, buttonNegative;
View view = LayoutInflater.from(context).inflate(resId, null, false);
labelTitle = view.findViewById(R.id.labelTitle);
labelMessage = view.findViewById(R.id.labelMessage);
buttonPositive = view.findViewById(R.id.buttonPositive);
buttonNegative = view.findViewById(R.id.buttonNegative);
if (Utils.isNotEmpty(titleText)) labelTitle.setText(titleText); //(HMI2Utils.isNotEmpty is a null check
if (Utils.isNotEmpty(message)) labelMessage.setText(message);
if (Utils.isNotEmpty(positiveText)) buttonPositive.setText(positiveText);
if (Utils.isNotEmpty(negativeText)) buttonNegative.setText(negativeText);
switch (type) {
case DANGEROUS:
labelTitle.setTextColor(ContextCompat.getColor(context, R.color.white));
}
buttonNegative.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
alertDialog.dismiss();
dialogListener.onNegativeButtonClick();
}
});
buttonPositive.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
alertDialog.dismiss();
dialogListener.onPositiveButtonClick();
}
});
Utils.hideSoftKeyboard((Activity) context);
ContextThemeWrapper ctw = new ContextThemeWrapper(context, R.style.MyDialogTheme);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctw);
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setView(view);
alertDialog = alertDialogBuilder.create();
Window window = alertDialog.getWindow();
if (window != null) {
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(ContextCompat.getColor(context, R.color.app_theme_color));
}
alertDialog.show();
}
and for xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rlRoot"
android:layout_width="736.15px"
android:layout_height="532.66px"
tools:ignore="Overdraw">
<View
android:id="#+id/focus_eater_dummy"
android:layout_width="1px"
android:layout_height="1px"
android:focusable="true" />
<ImageView
android:layout_width="736.15px"
android:layout_height="532.66px"
android:scaleType="fitXY"
android:src="your drawable" />
<RelativeLayout
android:id="#+id/container"
android:layout_width="736.15px"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="67.83px"
android:layout_marginRight="67.83px"
android:layout_marginTop="57.855px"
android:orientation="vertical">
<TextView
android:id="#+id/labelTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_horizontal"
android:maxLines="1"
android:text="#string/delete_message_string"
android:textColor="#color/white"
android:textSize="24sp" />
<TextView
android:id="#+id/labelMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="18px"
android:lineSpacingExtra="18px"
android:gravity="center_horizontal"
android:lineSpacingMultiplier="1"
android:text="#string/delete_message_string"
android:textColor="#color/white"
android:textSize="24sp" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/containerButtons"
android:layout_width="736.15px"
android:layout_height="532.66px"
android:weightSum="2"
android:gravity="bottom"
android:layout_gravity="bottom"
android:orientation="horizontal">
<TextView
android:id="#+id/buttonPositive"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="#dimen/margin_button_vertical_dai"
android:background="#drawable/popup_button_selector"
android:gravity="center"
android:textColor="#color/white"
android:textSize="32sp"
tools:text="OK" />
<TextView
android:id="#+id/buttonNegative"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp"
android:background="#drawable/popup_button_selector"
android:gravity="center"
android:text="Cancel"
android:textColor="#color/white"
android:textSize="32sp" />
</LinearLayout>
</FrameLayout>
make your custom changes and call the dialog like
new Dialog(context,
"Title 1",
"Message 2",
"OK",
"Cancel",
Dialog.Type.DANGEROUS,
new Dialog.DialogListener() {
#Override
public void onPositiveButtonClick() {
//implement Click here
}
#Override
public void onNegativeButtonClick() {
//implement Click here
}
}
);
dialog.dismiss();

Change theme to button

Hi I have 1 activity with 3 buttons,I have now created the ability to change the theme app, and up here all okay but I do not know how to go from buttoshape.xml to buttoshape_blue.xml
This is my theme:
<resources>
<style name="AppTheme.Blue" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_blue</item>
<item name="colorPrimaryDark">#color/primaryColorDark_blue</item>
<item name="colorAccent">#color/primaryAccent_blue</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.Red" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_red</item>
<item name="colorPrimaryDark">#color/primaryColorDark_red</item>
<item name="colorAccent">#color/primaryAccent_red</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
this my button in xml
<Button
android:id="#+id/magic_item"
android:text="Magic Item"
android:textColor="#FFFFFF"
android:textSize="25dp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
/>
and this is my buttonshape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="90%"
android:centerColor="#ec2127"
android:startColor="#CC1414"
android:endColor="#FFFFFF"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#FFFFFF"
/>
my Utility
public class Utility {
public static void setTheme(Context context, int theme) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt(context.getString(R.string.prefs_theme_key), theme).apply();
}
public static int getTheme(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getInt(context.getString(R.string.prefs_theme_key), -1);
}
}
and BaseActivity
public class BaseActivity extends AppCompatActivity {
private final static int THEME_BLUE = 1;
private final static int THEME_RED = 2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
updateTheme();
}
public void updateTheme() {
if (Utility.getTheme(getApplicationContext()) <= THEME_BLUE) {
setTheme(R.style.AppTheme_Blue);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.primaryColorDark_blue));
}
} else if (Utility.getTheme(getApplicationContext()) == THEME_RED) {
setTheme(R.style.AppTheme_Red);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.primaryColorDark_red));
}
}
}
}
You could create a custom theme attribute which would contain a reference to the background to use and set it to #drawable/buttonshape for AppTheme.Red and to #drawable/buttonshape_blue for AppTheme.Blue.
E.g. in values you could have an attrs.xml file in which there would be:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="buttonBackground" format="reference" />
</resources>
and in your themes.xml:
<style name="AppTheme.Blue" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_blue</item>
<item name="colorPrimaryDark">#color/primaryColorDark_blue</item>
<item name="colorAccent">#color/primaryAccent_blue</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="backgroundColor">#color/bianco</item>
<item name="buttonBackground">#drawable/buttonshape_blue</item>
</style>
<style name="AppTheme.Red" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_red</item>
<item name="colorPrimaryDark">#color/primaryColorDark_red</item>
<item name="colorAccent">#color/primaryAccent_red</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="buttonBackground">#drawable/buttonshape</item>
</style>
Your button in the layout file would look like this:
<Button
android:id="#+id/magic_item"
...
android:background="?attr/buttonBackground"
...
/>

Android: changing colour of floating label (hint) in TextInputLayout in error state

I want the floating label of TextInputLayouts to change colour (e.g. to red) when there is an error. I can change the colour of the error text, but it has no effect on the appearance of the floating label (unlike someone in some other thread claimed). I couldn't use selectors for the hint colour to solve this problem either, as there does not seem to be a state defined for errors. Does anyone have any idea how to do this without having to manually program the change on error events/create a new java class (with EditText as parent)?
Here are the stylings I defined:
<style name="EditTextFloatingLabel" parent="#android:style/TextAppearance">
<item name="android:textSize">#dimen/textsize_caption_small</item>
<item name="android:layout_marginBottom">8dp</item>
<item name="android:textColor">#color/input_text_color</item>
</style>
<style name="EditTextErrorText" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/error_color</item>
</style>
<style name="EditTextLayout">
<item name="android:textColorHint">#color/placeholder_color</item>
<item name="android:background">#drawable/input_field_background</item>
<item name="android:paddingBottom">#dimen/default_margin_bottom</item>
<item name="android:paddingStart">#dimen/default_margin_left</item>
<item name="android:paddingEnd">#dimen/default_margin_right</item>
</style>
<style name="EditTextTheme">
<item name="android:imeOptions">actionDone</item>
<item name="android:maxLines">1</item>
<item name="colorControlNormal">#color/primary_line_color</item>
<item name="colorControlActivated">#color/nordea_blue</item>
<item name="android:colorControlHighlight">#color/error_color</item>
<item name="android:textColorPrimary">#color/input_field_text</item>
<item name="android:textSize">#dimen/textsize_caption</item>
<item name="android:textColorHint">#color/placeholder_color</item>
</style>
<style name="EditText">
<item name="android:theme">#style/EditTextTheme</item>
<item name="android:textCursorDrawable">#drawable/cursor_blue</item>
<item name="android:paddingTop">#dimen/default_padding_top</item>
<item name="android:paddingStart">#dimen/payment_text_input_padding</item>
</style>
Usage:
<android.support.design.widget.TextInputLayout
android:id="#+id/input_field_error_wrapper_light"
style="#style/EditTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/testlogin_text_input_end_padding"
android:layout_marginStart="#dimen/testlogin_text_input_start_padding"
android:paddingTop="#dimen/default_padding_top"
app:hintTextAppearance="#style/EditTextFloatingLabel"
app:errorTextAppearance="#style/EditTextErrorText"
app:errorEnabled="true">
<EditText
android:id="#+id/input_field_light_error"
style="#style/EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#Input Field Disabled Light"
android:imeOptions="actionDone"
/>
</android.support.design.widget.TextInputLayout>
And this is what I see:
As I needed to perform some other actions as well when the layout was in error state, I decided to go with the solution of creating a custom error state and a custom TextInputLayout which can enter this state.
Code:
Defining the new error state in res/values/attrs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
...
<!-- custom states -->
<declare-styleable name="ErrorState">
<attr name="state_error" format="boolean" />
</declare-styleable>
</resources>
ErrorStateTextInputLayout class:
public class ErrorStateTextInputLayout extends TextInputLayout {
private boolean hasError = false;
private static final int[] ERROR_STATE = new int[]{R.attr.state_error};
public ErrorStateTextInputLayout(Context context) {
super(context);
}
public ErrorStateTextInputLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ErrorStateTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
protected int[] onCreateDrawableState(int extraSpace) {
int[] state = super.onCreateDrawableState(extraSpace + 1);
if (hasError) {
mergeDrawableStates(state, ERROR_STATE);
}
return state;
}
#Override
public void setError(#Nullable CharSequence error) {
if (error == null) {
setHasError(false);
} else {
setHasError(true);
}
super.setError(error);
}
public void setHasError(boolean error) {
this.hasError = error;
refreshDrawableState();
}
}
Selector for setting the hint text colour:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:color="#color/disabled_text_color" android:state_enabled="false" />
<item android:color="#color/error_color" app:state_error="true" />
<item android:color="#color/input_text_color" android:state_focused="true" />
<item android:color="#color/placeholder_color" />
</selector>
This blog post helped me a lot: http://code.neenbedankt.com/example-of-custom-states-in-android-components/
Try this..solid_red floating color.....
<style name="TextLabelInput" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/solid_red</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/solid_red</item>
<item name="android:duration">200</item>
<item name="android:textColorHighlight">#color/solid_red</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/solid_red</item>
<item name="colorControlNormal">#color/solid_red</item>
<item name="colorControlActivated">#color/solid_red</item>
<item name="colorPrimary">#color/solid_red</item>
<item name="colorPrimaryDark">#color/solid_red</item>
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
app:errorTextAppearance="#style/TextLabelInput"
>
hint text color manage over your main theme
which are colorPrimary and colorAccent
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>

Need a progressbar, which blocks other ui elements

I have an application that all screens are fragments and contained by the main container. I need a progressbar, which needs to block the other ui elements when it is visible. But the one below does allow the other ui elements to be clicked. How can I make it block the entire screen?
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false">
<RelativeLayout
android:id="#+id/loading_animation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:background="#color/transparent"
android:layout_gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</FrameLayout>
we have done that like :
mDialog = new ProgressDialog(getActivity(), R.style.MyDialogTheme);
mDialog.setCancelable(false);
mDialog.show();
by using this style :
<style name="MyDialogTheme" parent="android:Theme.Holo.Dialog">
<item name="android:alertDialogStyle">#style/CustomAlertDialogStyle</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textStyle">normal</item>
<item name="android:textSize">12sp</item>
</style>
add this to your relativeLayout (loading_animation):
android:clickable="true"
Create a common class Utility to reuse the code
public class Utility {
public static ProgressDialog getProgressDialog(Context context) {
ProgressDialog progressDialog = new ProgressDialog(context,
R.style.TransparentDialog);
progressDialog.setCancelable(false);
progressDialog
.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
progressDialog.setProgress(0);
return progressDialog;
}
}
Wherever you want progress bar just use this code
protected ProgressDialog dialog;
dialog = Utility.getProgressDialog(mContext);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
if (dialog != null) {
dialog.show();
}
To dismiss dialog
dialog.dismiss();

App name showing on top of Alert Activity popup

Im showing a popup alert activity, when select a notification from tray.
But on top it's showing the App name (MCP), with improper alignment.
I don't want the top part, just a normal dialog.
Manifest:
<activity
android:name=".activity.AlertDialogActivity"
android:configChanges="orientation|locale|screenSize|uiMode|fontScale"
android:excludeFromRecents="true"
android:theme="#style/AlertDialogTheme" />
Style:
<style name="AlertDialogTheme" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
Alert activity:
public class AlertDialogActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alert_dialog);
this.setFinishOnTouchOutside(false);
String message = getIntent().getExtras().getString("message");
TextView tvPushMessage = (TextView) findViewById(R.id.tvAlertMessage);
tvPushMessage.setText(message);
Button btnPushOk = (Button) findViewById(R.id.btnAlertOk);
btnPushOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#drawable/background_round_rectangle"
android:padding="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/tvAlertMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Message"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black" />;
<Button
android:id="#+id/btnAlertOk"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="#id/tvAlertMessage"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#drawable/btn_use"
android:text="#string/ok"
android:textColor="#color/white" />
</RelativeLayout>`
Also tried:
requestWindowFeature(Window.FEATURE_NO_TITLE);
and:
getWindow().setFeatureDrawableResource(Window.FEATURE_NO_TITLE, android.R.drawable.ic_dialog_alert)
before setContentView()
Just Add Following code in style.xml
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
or You can hide it Programmatically.
getSupportActionBar().hide();
Try this code (without using "android:")
<style name="Theme.MyDialog" parent="#style/Theme.AppCompat.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
I used this:
In AppCompatActivity onCreate() add following codeļ¼š
setTitle("")
and Add The following code in style.xml
<style name="PopupWindowTheme" parent="#style/Theme.AppCompat.Dialog.Alert">
<item name="android:windowBackground">#color/transparent</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">#style/AnimBottom</item>
</style>
Add requestWindowFeature in this way may be work proper.
First Call Super after add it.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.add__favourite_layout);
}

Categories

Resources