I'm trying to change the background color of an Android AlertDialog.
Every post I've seen is about changing the color of the AlertDialog, but not the background behind.
Any help would be appreciated.
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:background">#color/myColor</item>
and then apply it in the Builder constructor:
AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.MyDialogTheme)
...
.create();
for more info see see this post
you can reduce the dim Amount
dialog.getWindow().setDimAmount(0.5f);
To get a background color you need to make a custom Alert Dialog.
There is one way to do what you asked for but its not that much of a good solution
First, set custom dialog theme like this.
styles.xml
<style name="CustomDialogTheme" parent="android:Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
CustomDialog.java
Apply the theme and construct your custom_dialog view as follows.
public HTCustomDialog(Context context) {
super(context, R.style.CustomDialogTheme);
setContentView(R.layout.custom_dialog);
}
custom_dialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/main_solid_80">
<RelativeLayout
android:id="#+id/dialog_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#drawable/bg_popup"
android:padding="16dp">
</RelativeLayout>
Now that CustomDialog view is a full-screen view, set background of your root layout to whatever color you'd like.
I got this answer from here take a look .
Related
how is posible to do it, I actually have this code:
public void openDialog() {
final Dialog dialog = new Dialog(this); // Context, this, etc.
dialog.setContentView(R.layout.fragment_wrongpass_reg);
dialog.setTitle("cualquier cosa");
dialog.show();
}
I need to put the the back screen with alpha, making it almost transparent as in this image:
here is the image
You need to create a full screen dialog set it with a custom theme.
create a full screen dialog and set its content with inside padding.
something like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cb000000"
android:padding="20dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical"
....
....
YOUR CONTENT
....
..../>
</RelativeLayout>
The custom theme should be something like this one:
<style name="Dialog_Fullscreen">
<item name="android:windowActionBar">false</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
finally, set it to the dialog, like this:
final dialog = new Dialog(context, R.style.Dialog_Fullscreen);
I've got one activity with an image in a toolbar and an activity that is themed like a dialog with the same image in big. These are the layout files:
my_activity.xml:
...
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/my_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="centerCrop"
android:src="#drawable/my_drawable"
android:transitionName="#string/my_image_transition"
app:riv_oval="true" />
...
my_dialog_activity.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#id/my_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/my_drawable"
android:tint="#color/accent"
android:transitionName="#string/my_image_transition" />
</LinearLayout>
The dialog activity becomes a dialog by applying this theme in the manifest:
<style name="MyDialogActivity" parent="Theme.AppCompat.Light.Dialog.MinWidth">
<item name="windowNoTitle">true</item>
<item name="android:windowMinWidthMajor">#dimen/abc_dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">#dimen/abc_dialog_min_width_minor</item>
</style>
Both the activity and the dialog look exactly how I want them to look like.
Now I want to implement a shared element animation with these ImageViews: When the user clicks on the first activity's image, it has to grow and move into the middle of the screen so it fits the bigger dialog's image.
So I wrote this code:
Intent intent = new Intent(MyActivity.this, MyDialogActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
MyActivity.this, v, getString(R.string.my_image_transition)
);
startActivityForResult(intent, 999, options.toBundle());
} else {
startActivityForResult(intent, 999);
}
The animation does actually happen, but the moved image is only visible inside of the dialog's area. So you see an image that comes from the dialog's upper left corner, but you don't see it moving from the first activity outside of the dialog.
Here's a HTML version of how it should look like and what it currently looks like: https://jsfiddle.net/wutqdh9d/1/
The Share Element Animation was drawn in the second activity. As you use the Theme.AppCompat.Light.Dialog.MinWidth theme, the second activity's window size is smaller than the drawing area of animation.
Hence, just get rid of using the dialog theme. To change this below:
<style name="MyDialogActivity" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
The second activity layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#id/my_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="#drawable/your_icon"
android:transitionName="#string/my_image_transition"/>
Then it will be this effect(http://gph.is/1UzZZzV).
Hope it help.
Reference: https://stackoverflow.com/a/28508306/3171537
<style name="dialog_style_activity">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
Above style is work for me. Reference this style in manifest.xml.
I have a custom AlertDialog style that makes the AlertDialog box transparent. It works fine except that when I inflate my desired transparent layout into the alert dialog window, it shows up with a black background. My goal is to have a completely transparent AlertDialog to where it seems as if there are only 4 buttons floating rather than a frame.
Image one is what the custom dialog is giving me, image two is my desired or what I am aiming for.
Here is the code to the custom Dialog
<style name="CustomDialog" parent="android: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">false</item>
<item name="android:background">#android:color/transparent</item>
</style>
Here is what I am calling in my onCreate()
AlertDialog.Builder imageDialog = new AlertDialog.Builder(TimeLine.this, R.style.CustomDialog);
inflater = getLayoutInflater();
View view=inflater.inflate(R.layout.tabs, null);
AlertDialog a = imageDialog.create();
a.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
a.setView(view, 0, 0, 0, 0);
a.show();
Edit*
The code for the tabs layout xml is here
`
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/tabLayout"
android:background="#000000ff">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"
android:layout_marginTop="206dp"
android:layout_below="#+id/button4"
android:layout_alignStart="#+id/button4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button3"
android:layout_alignTop="#+id/button2"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button4"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="100dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="100dp" />
</RelativeLayout>
`
From testing to see what the source of the problem is, I have found out that it is true that the layout is transparent because when I change the background color of the layout, so does the alert dialog change. However when the layout is set to transparent, it seems that what is behind the inflated layout is black. And because of that I am unsure of what to do or whether it is the AlertDialog settings or my layout code.
The problem is that AlertDialog builder is actually not good for designing transparent dialog and will and always have this black background which is actually a Theme for it, instead use the Dialog to create a transparent theme instead.
sample:
Dialog alertDialog = new Dialog(this);
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.setContentView(R.layout.tabs);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.show();
Using Dialog does not require any theme manipulation for transparent background so it is basically easy.
Have you tried using something like this:
<style name="CustomDialog" parent="#android:style/Theme.Translucent">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
...
</style>
EDIT
Try this in java code
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Those who are having still problem creating custom transparent dialog or alert dialog, can use this combination. I also wanted to show custom background this is what worked for me.
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
example:-
/**
* alert dialog
*/
public class ToolTipView extends AlertDialog {
public ToolTipView(#NonNull Context context) {
super(context);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_tool_tip_view);
}
}
In your R.layout.tabs,
Replace
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/tabLayout"
android:background="#000000ff">
with
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/tabLayout"
android:background="#android:color/transparent">
I'm trying to make a custom progress bar with custom indeterminate view using animation_list with multiple images .. i've got it to work but it does something weird a part of the image is repeated like so ..
Here is the code:
Dialog dialog = new Dialog(getActivity(), R.style.CustomProgressDialog);
View customView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.custom_loader_layout, null, false);
dialog.setContentView(customView);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
Here is the layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:gravity="center"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/imgProgreso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:background="#android:color/transparent"
android:indeterminateDrawable="#drawable/loader_drawable" />
<TextView
android:id="#+id/txtmensajedialogprogress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:background="#android:color/transparent"
android:gravity="center_vertical|center_horizontal"
android:text="Wait ..."
android:textColor="#android:color/black"
android:textSize="15dp"
android:textStyle="normal" />
and here is the custom style
<style name="CustomProgressDialog" parent="#android:Theme.Dialog" >
<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:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:background">#android:color/transparent</item>
</style>
NOTE: worth mentioning this problem seems to happen when i use the custom style to make background transparent
Any help would be really appreciated :)
The answer was using an ImageView instead of a a custom layout resource while setting a background for the animation-list for some reason drawing that background for the animation-list got messed up.
It simply goes something like that ..
Dialog dialog = new Dialog(getActivity(), R.style.CustomProgressDialog);
ImageView customView = new ImageView(getActivity());
customView.setBackgroundResource(R.drawable.bg_loader);
customView.setImageDrawable(getResources().getDrawable(R.drawable.custom_loader));
while R.drawable.custom_loader is the animation-list
I want to customize all dialogs, alertDialogs and spinner. I want to change the color of text and the background of the title bar.
I try to explain better:
I want the text (JOLLY BAR DI ...) to be white and the background of the title (from the top of the dialog to the soft-blue line below the title included) to be blue (#044592).
How can I do it?
Ok, I've almost solved the problem (I'm answering my own question because it may help others with the same problem as mine).
The problem remains for spinners, DatePickers etc.
For the AlertDialogs I do something like this:
AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this, AlertDialog.THEME_HOLO_LIGHT);
//Then I do what I need with the builder (except for setTitle();
LayoutInflater inflater = getLayoutInflater();
View view=inflater.inflate(R.layout.dialog_custom_title, null);
TextView title = (TextView)view.findViewById(R.id.myTitle);
title.setText("Title I want to show");
builder.setCustomTitle(view);
AlertDialog alert = builder.create();
alert.show();
dialog_custom_titile.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#044592" >
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myTitle"
android:layout_width="fill_parent"
android:textSize="20dp"
android:layout_height="70dp"
android:layout_marginLeft="25dp"
android:paddingTop="22dp"
android:textColor="#android:color/white"
android:textStyle="bold" />
</RelativeLayout>
for the Activities that I want to look like Dialogs I do like this:
I declare them in the Manifest.xml as follows:
<activity
android:name="com.aveschini.AnotherActivity"
android:screenOrientation="portrait"
android:label="My Dialog"
android:theme="#style/MyDialog"
android:windowSoftInputMode="adjustPan" />
then, in the res/values/styles.xml file I do like this:
<style name="AppTheme" parent="android:Theme.Holo.Light" />
<style name="MyDialog" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowTitleStyle">#style/DialogWindowTitle</item>
</style>
<style name="DialogWindowTitle">
<item name="android:textAppearance">#style/TextAppearance.DialogWindowTitle</item>
<item name="android:background">#044592</item>
</style>
<style name="TextAppearance.DialogWindowTitle" parent="android:TextAppearance">
<item name="android:textColor">#android:color/white</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">20sp</item>
</style>
I still get the light blue divider between the title and the body... still working on it.
As already said, I still don't know how to deal with Spinners, DatePicker, etc...
That's the result:
AlertDialog:
And an Activity with the look of a dialog: