Change the background color of a pop-up dialog
If you just want a light theme and aren't particular about the specific color, then you can pass a theme id to the AlertDialog.Builder constructor.
AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT)...
or
AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)...
Alert Dialog background theme/Color
Create your style in your styles.xml
file as follows.
<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
<item name="android:textColor">@color/White</item>
<item name="android:textStyle">bold</item>
<item name="android:headerDividersEnabled">true</item>
<item name="android:typeface">normal</item>
<item name="android:background">@color/colorPrimaryDark</item>
</style>
Then Create Alert Dialog
using Builder as follows
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this/getActvity(), R.style.AlertDialogCustom));
Here passing the current class Context and style to the ContextThemeWrapper
class constructor.
android how to change background colour in AlertDialog
finally i did it..created a custom dialog..,and its working
private void showdialog() {
final Dialog dialog = new Dialog(RegisterScreen.this, R.style.CenterDialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog_layout);
dialog.setCancelable(true);
final Spinner sp = (Spinner) dialog.findViewById(R.id.spinner);
ArrayAdapter<String> adapter_chocolate = new ArrayAdapter<String>(RegisterScreen.this,
android.R.layout.simple_spinner_item, CountryCodeArray);
sp.setAdapter(adapter_chocolate);
sp.setOnItemSelectedListener(new MyOnItemSelectedListener());
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(RegisterScreen.this);
//alertDialogBuilder.setTitle("Missing data");
alertDialogBuilder.setCancelable(true); //if you set this false, the user will not be able to cancel the dialog by clicking BACK button
// alertDialogBuilder.setMessage("You haven't set the quantity!");
/*alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialogBuilder.show(); //don't forget to show the dialog! It is a common mistake.
*/
Button btnCancel = (Button) dialog.findViewById(R.id.Button_Cancel);
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
dialog.show();
}
its working...:)
How to change the Android AlertDialog selection background color
See below code for style:
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:background">@color/myColor</item>
</style>
Now this style apply on dialog:
AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.MyDialogTheme)
Android: How can I change AlertDialog Title Text Color and Background Color without using custom layout?
You can use custom title to your alert dialog:
TextView textView = new TextView(context);
textView.setText("Select an option");
textView.setPadding(20, 30, 20, 30);
textView.setTextSize(20F);
textView.setBackgroundColor(Color.CYAN);
textView.setTextColor(Color.WHITE);
final CharSequence[] items = {"Visiting Card", "Prescription Letter"};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCustomTitle(textView);
builder.setItems(items, (dialog, item) -> {
}).show();
custom alert dialog background color
try to set dialog theme like this in styles.xml
<style name="dialogTheme" parent="android:Theme.Holo.Dialog">
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
</style>
java code
Dialog dialog = new Dialog(activity, R.style.dialogTheme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.your_dialog_layout);
activity.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Related Topics
Highlight Listview Selected Row
Rotate an Yuv Byte Array on Android
How Does Native Android Code Written for Arm Run on X86
Android Sms Receiver Not Working
Android Intent.Getstringextra() Returns Null
Replacing Glreadpixels with Egl_Khr_Image_Base for Faster Pixel Copy
How to Add External Fonts to Android Application
Determine When a Viewpager Changes Pages
Get All Child Views Inside Linearlayout at Once
How to Scroll to Bottom in a Scrollview on Activity Startup
Audiotrack, Soundpool or Mediaplayer Which Should I Use
Getting Permission Denial Exception
Programmatically Add View One Below Other in Relative Layout