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);
Related
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 .
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've been trying to set a basic (not at all custom) dialog box using a fragment, and having difficulties. As you can see in the attached in image, the background shadow isn't correct and the title has white at the left and right hand side.
Following advice from How to style AlertDialogs like a pro I tried setting the alert dialog style through my app, and copying the style out of the Android SDK but this doesn't seem to make much difference.
<!-- Local copy of android:Theme.Holo.Dialog.Alert -->
<style name="Theme_Holo_Dialog_Alert" parent="#android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">#drawable/dialog_full_holo_light</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:buttonBarStyle">#android:style/Holo.Light.ButtonBar.AlertDialog</item>
<item name="android:borderlessButtonStyle">#android:style/Widget.Holo.Light.Button.Borderless.Small</item>
<item name="listPreferredItemPaddingLeft">16dip</item>
<item name="listPreferredItemPaddingRight">16dip</item>
<item name="android:windowMinWidthMajor">#android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">#android:dimen/dialog_min_width_minor</item>
</style>
<!-- Local copy of android:DialogWindowTitle.Holo -->
<style name="DialogWindowTitle_Holo">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">#android:style/TextAppearance.Holo.DialogWindowTitle</item>
</style>
and I tried setting the style directly using
ContextThemeWrapper ctw = new ContextThemeWrapper(getActivity(), R.style.Theme_Holo_Dialog_Alert);
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
and also
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_LIGHT);
None of which make a difference to the background shadow or the title styling.
Any ideas?
Update 1: The layout of the dialog is set using a fragment and added to the builder as a view:
LayoutInflater inflater = getActivity().getLayoutInflater();
_layoutView = inflater.inflate(R.layout.fragment_edit_cycles, null);
builder.setView(_layoutView);
using the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="10dp"
android:paddingBottom="20dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editStageCyclesSpin" />
</LinearLayout>
Update 2: Removed the padding and changed the height/width in response to Alok Nair
I removed the padding and changed the layout width and height but unfortunately this had no effect on the white space in the title
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editStageCyclesSpin" />
</LinearLayout>
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: