I created a custom alertdialog. I used a half-transparent shape for background.
And its button is fully transparent in unfocused state.
The button is also customized by using a solid colored shape.
My problem is, there are white lines in two sides of the button where the default button originally located.
I tried to manipulate dividers by changing its color, width etc.
I tried:
android:showDividers="none"
But none of my operations worked.
So I am thinking these two lines may not be dividers.
But I can not find what are these and how to hide them.
Here is my java code:
AlertDialog.Builder alert = new AlertDialog.Builder(this, R.style.Theme_Organic_Dialog_Alert);
alert.setMessage(R.string.channel_warning_message);
alert.setNeutralButton(R.string.okay, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//sthLikeDoNothing();
}
});
alert.show();
My theme:
<style name="Theme_Organic_Dialog_Alert">
<item name="android:windowBackground">#drawable/alert_dialog_bg</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:buttonBarButtonStyle">#style/Organic_Button_AlertDialog</item>
<item name="android:buttonBarStyle">#style/Organic_ButtonBar_AlertDialog</item>
<item name="android:alertDialogStyle">#style/AlertDialog_Organic</item>
<item name="android:textAppearanceMedium">#style/TextAppearance_Organic</item>
</style>
And my button styles:
<style name="Organic_ButtonBar_AlertDialog" parent="#android:style/Holo.ButtonBar.AlertDialog">
<item name="android:background">#android:color/transparent</item> <!-- ButtonBar background transparency -->
</style>
<style name="Organic_Button_AlertDialog" parent="#android:style/Holo.ButtonBar.AlertDialog"> <!-- Custom drawable button -->
<item name="android:background">#drawable/alert_dialog_button_selector</item>
<item name="android:textColor">#drawable/alert_dialog_button_txt_color_selector</item>
<item name="android:fontFamily">roboto-regular</item>
<item name="android:textSize">20sp</item>
</style>
These are the lines I want to hide:
I found what causes those divider lines. It was because I was setting Holo as the parent of my button styles.
Here,
<style name="Organic_ButtonBar_AlertDialog" parent="#android:style/Holo.ButtonBar.AlertDialog">
and here,
<style name="Organic_Button_AlertDialog" parent="#android:style/Holo.ButtonBar.AlertDialog">
Now I removed parents and the lines are gone.
Related
hello, I have an alert dialog. the buttons are purple. yes I can change the color of the text inside using:
alertDialog.getButton(Dialog.BUTTON_NEGATIVE).
setTextColor(Color.parseColor("#000000"));
however when they are touched, there is a purple hue that forms.
I want the hue to be blue like the main accent of my app and the text to be black.
this is my alert style:
<style name="MyCustomAlert2" parent="Theme.MaterialComponents.Dialog.Alert">
<item name="colorAccent">#color/materialBlue</item>
<item name="android:textColorPrimary">#android:color/black</item>
<item name="android:windowBackground">#drawable/custom_alert2</item>
<item name="colorControlNormal">#android:color/black</item>
<item name="colorControlActivated">#color/materialBlue</item>
<item name="textColorAlertDialogListItem">#android:color/black</item>
</style>
note: none of the colors linked above are purple.
thanks for the help
Use new theandroidx.appcompat.app.AlertDialog and the Material components for android library.
Just use something like:
new MaterialAlertDialogBuilder(context)
.setTitle("...")
.setMessage("....")
.setPositiveButton("Ok", /* listener = */ null)
.setNegativeButton("Cancel", /* listener = */ null)
.show();
Then you can customize the style with something like:
<!-- Alert Dialog -->
<style name="MyThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="#style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="buttonBarPositiveButtonStyle">#style/PositiveButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">#style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
</style>
and here you can change each button:
<style name="PositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#000000</item>
<item name="backgroundTint">#color/selector_bt</item>
</style>
You can set the style globally in your app theme using:
<item name="materialAlertDialogTheme">#style/MyThemeOverlay.MaterialComponents.MaterialAlertDialog</item>
or you can use the constructor:
new MaterialAlertDialogBuilder(context,
R.style.MyThemeOverlay_MaterialComponents_MaterialAlertDialog)
Can we modify/custom ourBiometricPrompt?
For example right now i use smth like this:
BiometricPrompt.Builder(AppResources.appContext)
.setTitle("title")
.setSubtitle("subTitle")
.setDescription("description")
.setNegativeButton("Cancel", AppResources.appContext?.mainExecutor,
DialogInterface.OnClickListener { dialogInterface, i -> biometricCallback.onAuthenticationCancelled() })
.build()
.authenticate(CancellationSignal(), AppResources.appContext?.mainExecutor,
BiometricCallbackV28(biometricCallback))
Do I have the ability to change the style of the text, title, negativeButton color?
Update2: beta01
The change with the alpha version was that the fingerprint dialog uses android.app.AlertDialog and the new beta01 uses androidx.appcompat.app.AlertDialog which has a private style.
Then to override that style we have to override androidx.appcompat.R.attr.alertDialogTheme reference in our styles.xml, we can do it replacing <item name="android:alertDialogTheme">#style/CustomAlertTheme</item> by <item name="alertDialogTheme">#style/CustomAlertTheme</item> in my case thay I only wanted to change the button text color, I just added <item name="buttonBarNegativeButtonStyle">#style/NegativeButtonStyle</item> and the same for posivtive, because replacing alertDialogTheme changes other things that I did not want to.
My styles.xml now:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColor">#color/black</item>
<item name="android:buttonStyle">#style/WibleButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">#style/NegativeButtonStyle</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#color/dark_blue</item>
</style>
Update: beta01
This trick is not working anymore. I'll try if I can find another way to do it.
I found two ways to do it, none of these are specific for the BiometricPrompt, one is to override the theme button style:
<item name="android:buttonStyle">#style/CustomButtonStyle</item>
another option is to override your alert dialog theme:
AppTheme style
<item name="android:alertDialogTheme">#style/AlertDialogTheme</item>
<style name="AlertDialogTheme" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="android:buttonBarNegativeButtonStyle">#style/NegativeButtonStyle</item>
<item name="android:buttonBarPositiveButtonStyle">#style/PositiveButtonStyle</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textSize">10sp</item>
<item name="android:textColor">#color/primary_text</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#color/primary_text</item>
</style>
And then you can apply a specific theme to a specific activity. Maybe they could open the API to allow styles, but I had to change the color because it was impossible to see the buttons (everything was white) and this is what I found to solve my problem. I hope it helps you.
You can't set properties on the prompt that aren't exposed through its Builder - the UI is provided by the system, and is designed to be uniform throughout all apps.
This is sort of the main point of this API, this way the user becomes familiar with the prompt and knows that whatever they're interacting with is safe to use.
Can we modify/custom our BiometricPrompt?
The BiometricPrompt uses the "buttonStyle" style that is set for your theme, which you can adjust in the styles.xml
Keep in mind that this is the default button style, so if you do not want other buttons to change you would have to assign buttons etc. their own style. (and dialogs etc.)
For example, if you only want the text color to be different for the BiometricPrompt, you could do something like this:
<style name="myTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="buttonStyle">#style/ButtonPrimaryStyle</item>
</style>
<style name="ButtonPrimaryStyle" parent="ButtonParentStyle">
<item name="android:textColor">454545</item>
</style>
<style name="ButtonPrimaryStyleMain" parent="ButtonPrimaryStyle">
<item name="android:textColor">e2e2e2</item>
</style>
This would make the BiometricPrompt have a dark grey text for the cancel button, while every button with the "ButtonPrimaryStyleMain" style will have a lightgrey, almost white, text color.
You would also have to assign this theme to your application in the manifest.
<application
android:theme="#style/myTheme"
EditText style
<style name="MyEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:textCursorDrawable">#null</item>
<item name="android:textColor">#color/color_states_blackish</item>
<item name="android:fontFamily">#font/sfd_medium</item>
<item name="android:background">#drawable/edit_white_gray_x_normal_rounded</item>
<item name="android:height">#dimen/general_view_height</item>
</style>
Dialog style
<style name="MyAlertDialogTheme" 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/text_color_blackish</item>
<item name="android:fontFamily">#font/sfd_regular</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#color/text_color_blackish</item>
<item name="android:fontFamily">#font/sfd_bold</item>
</style>
Dialog code
final EditText editText = new EditText(new android.view.ContextThemeWrapper(getContext(),R.style.MyEditTextStyle));
final FrameLayout layout = new FrameLayout(getContext());
int padding = getContext().getResources().getDimensionPixelSize(R.dimen.standard_wall_space);
int paddingView = getContext().getResources().getDimensionPixelSize(R.dimen.standard_view_space);
layout.setPadding(padding,paddingView,padding,paddingView);
layout.addView(editText);
editText.setHint(R.string.type_here);
new AlertDialog.Builder(getContext(),R.style.MyAlertDialogTheme)
.setTitle("Enter Your Unit")
.setView(layout)
.setPositiveButton("Add", (dialog, whichButton) -> {
String value = editText.getText().toString();
MyApp.showToast("Unit-"+value);
})
.setNegativeButton("Cancel", null).show();
What I got following kind of pointers with background same as EditText, I remove them ContextThemeWrapper then It shows correctly but I need change the background using style?, Why is this happening? This is dialog inside fullscreen dialog? Any solution? Thanks
The problem is that the android:background parameter in your theme is applied to everything inside the EditText. For me the solution was in removing that parameter from the style.
Looks like bugg, selector popup window get wrong background style, Don't use ContextThemeWrapper, style then it shows normally, set background programmatically.
final EditText editText = new EditText(getContext());
editText.setBackgroundResource(R.drawable.edit_white_gray_x_normal_rounded);
editText.setTextColor(ContextCompat.getColor(getContext(),R.color.color_states_blackish));
Additional to other answers here, it also occurs when we set background in the app theme in style.xml. Another solution I found was to replace android:background with android:backgroundTint of the background color and set android:backgroundTintMode to multiple.
Put this in styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="android:backgroundTint">#FFFFFF</item>
<item name="android:backgroundTintMode">multiply</item>
</style>
or in the view tag whose background color you want to change:
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#FFFFFF"
android:backgroundTintMode="multiply" />
I am having problems with the AlertDialog. The buttons doesn't use the accentColor to set the button text color any more.
I am using the newest support library, v24.2.1. I am styling my dialogs in my styles.xml the following way:
<style name="Base.Theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:alertDialogTheme">#style/Widget.DialogStyle</item>
<item name="alertDialogTheme">#style/Widget.DialogStyle</item>
</style>
and the Widget.DialogStyle looks like this:
<style name="Widget.DialogStyle" parent="#style/Theme.AppCompat.Light.Dialog.Alert">
<item name="android:colorAccent" tools:targetApi="lollipop">#color/primaryColor</item>
<item name="colorAccent">#color/primaryColor</item>
<item name="android:textColorPrimary">#color/primaryText</item>
<item name="android:textColor">#color/primaryText</item>
<item name="android:background">#color/backgroundColor</item>
<item name="android:textAppearanceLarge">#color/primaryText</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
</style>
On app API's lower than 24 the dialog buttons are colored with the colorAccent but on API 24 this is no more the behaviour (the text is black, should be orange). See the following screenshot.
Is there anybody that knows how to get the accentColor back on the buttons?
Thank you.
For some AlertDialog implementations, the buttons are contained in a ButtonBar and take their style from buttonBarButtonStyle. So you have to override the settings you inherit from the parent theme (Theme.AppCompat.Light.Dialog.Alert).
Add the following item to Widget.DialogStyle:
<item name="buttonBarButtonStyle">#style/MyButtonStyle</item>
and add another style named MyButtonStyle like this:
<style name="MyButtonStyle" parent="Widget.AppCompat.Button.Borderless">
<!-- Set background drawable and text size of the buttons here
<item name="android:background">#color/my_dialog_dark</item>-->
<item name="android:textSize">18sp</item>
<!-- this is the button text color! -->
<item name="android:textColor">#color/primaryColor</item>
</style>
EDIT
Thanks to kirtan403 for pointing this out: you can also use another parent style for the buttons if Widget.AppCompat.Button.Borderless does not meet your requirements.
An example by nicola.v...#icapps.com using Widget.AppCompat.Button.ButtonBar.AlertDialog as parent style for the buttons can be found under the AOSP Issue 220699: colorAccent not applied to AlertDialog buttons on Android N.
Be sure you are importing the correct AlertDialog:
import android.support.v7.app.AlertDialog
Also try inflating the dialog with another AlertDialog.Builder constructor:
android.support.v7.app.AlertDialog.Builder#Builder(android.content.Context, int)
which means, the second parameter is the style of the dialog:
mDialog = new AlertDialog.Builder(context, R.style.Widget.DialogStyle).create();
EDIT:
Sharing the code, that I use to show alert Dialog:
public AlertDialog showSimpleDialog(Context context, String title, String message, String btnOk, DialogInterface.OnClickListener handler) {
if (mDialog != null && mDialog.isShowing()) {
mDialog.dismiss();
mDialog = null;
}
mDialog = new AlertDialog.Builder(context, R.style.AppTheme_Dialog).create();
mDialog.setTitle(title);
mDialog.setMessage(message);
mDialog.setButton(DialogInterface.BUTTON_POSITIVE, btnOk, handler);
mDialog.setCanceledOnTouchOutside(false);
mDialog.show();
return mDialog;
}
and the style:
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#color/colorPrimary</item> //blue
<item name="android:textColorPrimary">#color/primary_text_material_light</item> //black
<item name="android:windowMinWidthMajor">97%</item>
<item name="android:windowMinWidthMinor">97%</item>
</style>
and the buttons are blue. Tested on emulator API 24.
Is there a way I can change all the alert dialogs appearing in my Android application? I want to change the dialogs that are system generated as well (like the Edit Text dialog that opens up when you long tap on any EditText). I want to change the title font color and size of all the dialogs in my app.
Is there a way to do it?
I have tried setting android:alertDialogTheme in my theme. But it seems to be not working. Code following -
<style name="Theme.DLight" parent="android:Theme.Light.NoTitleBar">
<item name="android:alertDialogTheme">#style/DialogStyle</item>
</style>
and
<style name="DialogStyle" parent="android:Theme" >
<item name="android:windowBackground">#drawable/background_holo_light</item>
<item name="android:textColor">#014076</item>
</style>
EDIT
I'm not invoking a dialog from my code. It's just the default dialog
that appears when you long click on any EditText. Generally it
contains the keyboard options like Select word, Select all, Input
method etc.
In you dialog theme, the attribute you need to modify windowTitleStyle. There, reference a style for your title and define a text appearance for this title. For example, to display your title red and bold:
<style name="AppTheme" parent="#android:style/Theme.Holo">
...
<item name="alertDialogTheme">#style/AppTheme.AlertDialog</item>
</style>
<style name="DialogStyle" parent="#style/Theme.Holo.Dialog.Alert">
...
<item name="android:windowTitleStyle">#style/DialogWindowTitle_Custom</item>
</style>
<style name="DialogWindowTitle_Custom" parent="#style/DialogWindowTitle_Holo">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">#style/TextAppearance_DialogWindowTitle</item>
</style>
<style name="TextAppearance_DialogWindowTitle" parent="#android:style/TextAppearance.Holo.DialogWindowTitle">
<item name="android:textColor">#android:color/holo_red_light</item>
<item name="android:textStyle">bold</item>
</style>
If you want to style a little bit more your AlertDialog, I wrote a blog post detailing the steps.
In styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
//All your other styles and add the one mntioned below.
<item name="alertDialogTheme">#style/AlertDialogStyle</item>
</style>
In the styles of AlertDialog add:
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/primary_text</item>
<item name="android:editTextColor">#color/primary_text</item>
<item name="android:background">#color/white</item>
<item name="android:windowTitleStyle">#style/TextAppearance.AppCompat.Title</item>
</style>
windowTitleStyle is important to add as it will give your title that effect that you need.
Now simply use this Theme in your AlertDialog in any activity that you want like below:
AlertDialog.Builder dialog = new AlertDialog.Builder(this, R.style.AlertDialogStyle);