Remove alert dialog border in custom Dialog - android

In my application i am using custom dialog .my dialog have rounded rectangle border and i can not remove that.please help me to set style for that to remove border. Thanks
public class myDialog extends Dialog
{
private String mMessage = "";
public myDialog(Context context, String message)
{
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
View v = getLayoutInflater().inflate(R.layout.dialog, null);
mMessage = message;
setCancelable(false);
setCanceledOnTouchOutside(false);
setContentView(v);
getWindow().setLayout(300,150);
getWindow().setBackgroundDrawableResource(R.);
}
}
My dialog cutom Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/dialog"
>
</LinearLayout>

This has been a long time frustrating issue with dialogs in Android. The only way I've been able to solve it, is by extending DialogFragment instead of Dialog and adding the following:
YourDialog.java
Dialog dialog = new Dialog(getActivity(), R.style.ActivityDialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
styles.xml
<style name="ActivityDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#null</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowTitleStyle">#style/ActivityDialog</item>
</style>

android:border = "invisible"
or transparent. You can find the info online

Related

How to make an alert dialogue transparent in android

I am using an alert dialog for displaying some checkboxes.I need a TRANSPARENT view for the whole alertview and for it contents.I tried many way...but not helps me...can anybody help me...any help will be highly apppreciated....
code for creating alert dialogue in java
Context c = getParent();
m_adapter = new Intrested_in_adapter(
Requestclass.this,
R.layout.intrestedin, offferList);
// Dialog dialog = new Dialog(this, R.style.NewDialog);
// mDialog = new AlertDialog.Builder(c,R.style.NewDialog);
mDialog = new AlertDialog.Builder(c);
mDialog.setTitle("Intrested In");
mDialog.setAdapter(m_adapter,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int item) {
}
});
alertDialog = mDialog.create();
Log.e(tag,"before background setting");
// alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Log.e(tag,"after background setting");
alertDialog.show();
xml for alert dialogue(intrestedin.xml)
<?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"
android:orientation="vertical"
>
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
/>
</LinearLayout>
May be this helps
<?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"
android:orientation="vertical"
android:background="#android:color/transparent" //make background transparent here by using this line
>
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
/>
<style name="TransparentDialog">
<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>
use in java
Dialog dialog = new Dialog(this, R.style.TransparentDialog);
Hope this will help you!!..
You can just set a default android theme so, there is no need to set NoTitleBar in extra params, then try a once it will working.
dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);

Changing dialogfragment background color (Using the Android Holo Colors Generator Xml Template)

All my theme is working beside my dialogfragment background.
I try to make my dialogFragment background black but i'm doing something wrong.
Here what i got so far in the theme xml (Note that i trunked the top and the bottom of it):
<style name="easydealtheme" parent="#style/_easydealtheme"/>
<style name="_easydealtheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:editTextBackground">#drawable/easydealtheme_edit_text_holo_light</item>
<item name="android:dropDownListViewStyle">#style/Listviewdropdowneasydealtheme</item>
<item name="android:textViewStyle">#style/Textvieweasydealtheme</item>
<item name="android:editTextStyle">#style/Edittexteasydealtheme</item>
<item name="android:alertDialogTheme">#style/Dialogeasydealtheme</item>
...
Here is what i got in the Styles xml for my dialog :
<style name="Dialogeasydealtheme" parent="android:Theme.Holo.Dialog">
<item name="android:textColor">#FFFFFF</item>
<item name="android:windowBackground">#color/test</item>
</style>
Here is the code that show the dialogFragment :
public static void ShowPhotoDialog(String title,File photoFile, FragmentManager fragM)
{
FragmentPhotoDialog photoD = new FragmentPhotoDialog();
FragmentTransaction fTX = fragM.BeginTransaction();
photoD.SetStyle(DialogFragmentStyle.NoFrame, EasyDeal_Android.Resource.Style.easydealtheme);
photoD.SetTile(title);
photoD.SetPhotoFile(photoFile);
photoD.Show(fTX, "Dialog");
}
Here the result which is not working (The white should be black ) :
I went crazy finding a solution for this problem until I came across a solution.
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Setup the layout
LayoutInflater inflater = getActivity().getLayoutInflater();
final View root = inflater.inflate(*"YOUR LAYOUT"*, null);
root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
//Customizing the dialog features
final Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(root);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(getResources().getColor(*"YOUR SELECTED COLOR"*)));
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
return dialog;
}
Try changing the alert dialog background as
<style name="Dialogeasydealtheme" parent="android:Theme.Holo.Dialog">
<item name="android:textColor">#FFFFFF</item>
<item name="android:background">#color/black</item>
</style>
Let me know if see any issue.
I find a solution not my favorite though but it will do.
I added a background to my layout. Here is the code on my main linearLayout:
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:orientation="vertical"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="#+id/liDialogPhoto"
p1:background="#drawable/easydealtheme_tilesbg">
I can now continue using no frame having a nice colored background !
Thanks for the help !

Android make a dialog appear in fullscreen

I need the dialog to fill the screen except for some space at the top and the bottom.
I've search for a solution but couldn't find one probably because I'm declaring it in an onClickListener.
Can someone please give a solution?
Activity code:
sort.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder sort = new AlertDialog.Builder(HomeScreen.this);
// Get the layout inflater
LayoutInflater inflater = HomeScreen.this.getLayoutInflater();
View sortView = inflater.inflate(R.layout.sort_layout, null);
sort.setView(sortView);
sort.create().show();
}
});
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="50dp"
android:layout_marginTop="50dp"
android:background="#color/white"
android:orientation="vertical" android:layout_gravity="center">
+ some more stuff here I dont think it's relevant
</LinearLayout>
here set your screen width and width to the dialog
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = width;
lp.height = height;
dialog.getWindow().setAttributes(lp);
or in your styles create a style like this then
<style name="DialogTheme" parent="android:Theme.Dialog">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
</style>
create a dialog object like this
dialog = new Dialog(this, R.style.DialogTheme);
Edit ::
get width and height like this for any device it will fills..
WindowManager manager = (WindowManager) getSystemService(Activity.WINDOW_SERVICE);
int width, height;
LayoutParams params;
if (Build.VERSION.SDK_INT > VERSION_CODES.FROYO) {
width = manager.getDefaultDisplay().getWidth();
height = manager.getDefaultDisplay().getHeight();
} else {
Point point = new Point();
manager.getDefaultDisplay().getSize(point);
width = point.x;
height = point.y;
}
first Make custom style for dialog in style.xml file:
<style name="full_screen_dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
Then after set this theme to your Alert Dialog:
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.full_screen_dialog));
Or You can call new Activity and Give this Custom style to that activity as a theme in your manifest file...
This may helpful for someone.
I want a dialog to take full width of screen. searched a lot but nothing found useful. Finally this worked for me:
mDialog.setContentView(R.layout.my_custom_dialog);
mDialog.getWindow().setBackgroundDrawable(null);
after adding this, my dialog appears in full width of screen.
Make object like below theme
Dialog objD = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
Dialog dialog2 = new Dialog(context, R.style.DialogTheme);
dialog2.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog2.getWindow().setBackgroundDrawable(null);
dialog2.setContentView(R.layout.dialog_img);
WindowManager.LayoutParams lp = dialog2.getWindow().getAttributes();
Window window = dialog2.getWindow();
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(lp);
lp.gravity = Gravity.CENTER;
final ImageView imgprofile=(ImageView)dialog2.findViewById(R.id.img_centre);
Picasso.with(context)
.load(arrayImages.get(position).get("image"))
.resize(800,1000)
.centerInside()
.into(imgprofile, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
imgprofile.setImageResource(R.drawable.user);
}
});
dialog2.show();
And in your dialog_img.xml file add an Imageview with scaleType(fitXY).
I think you shoud try this one:
Inside the dialogFragment:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}
The simplest way of creating a full screen dialog, create a style like this:
<style name="DialogFullScreenTheme" parent="Theme.AppCompat.Light.DialogWhenLarge">
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
</style>
then:
dialog = new Dialog(this, R.style.DialogFullScreenTheme);

Style attributes of custom styled AlertDialog

I am trying to style my AlertDialog and I have been able to change most of it through styles and xml declarations... but there are still a few issues:
How do I change the area around the title bar from black to my custom color?
How do I change the outer background to transparent (the outside part that is blue the the shadow drops upon)
How do I change the buttons so they do not overlap the black border around the alert message?
here is the function I have in my RootActivity (my activities extend this one)
public static void showNoConnectionDialog(Context ctx1) {
final Context ctx = ctx1;
LayoutInflater factory = LayoutInflater.from(ctx);
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(ctx, R.style.SetdartDialog));
builder.setView(factory.inflate(R.layout.alert_dialog, null))
.setIcon(R.drawable.icon)
.setCancelable(true)
.setMessage(R.string.check_wireless_settings)
.setTitle(R.string.no_connection)
.setPositiveButton(R.string.myes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
ctx.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
})
.setNegativeButton(R.string.mno, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
return;
}
})
.show();
}
here a snippet from styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.WhiteBackground" parent="android:Theme">
<item name="android:windowBackground">#null</item>
<item name="android:background">#android:color/white</item>
<!-- Dialog attributes
<item name="alertDialogStyle">#style/AlertDialog</item> -->
</style>
<style name="SetdartDialog">
<item name="android:background">#color/sd_blue</item> <!-- MUST HAVE with white bg-->
<!--<item name="android:windowBackground">#color/sd_blue</item> -->
<!--<item name="android:windowBackground">#color/transparent</item> needed with white bg ? -->
<item name="android:windowFrame">#color/transparent</item><!-- not sure what this changes-->
<item name="android:textColor">#android:color/black</item>
<item name="android:windowNoTitle">true</item>
<item name="android:textSize">10sp</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#color/transparent</item>
<item name="android:windowTitleStyle">#style/setwindowTitleStyle</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:gravity">center_vertical|center_horizontal</item>
<!--<item name="android:colorBackgroundCacheHint">#android:color/white</item>-->
</style>
<style name="setwindowTitleStyle">
<item name="android:textColor">#android:color/white</item>
<item name="android:background">#color/sd_blue</item>
</style>
</resources>
Also R.layout.alert_dialog
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/screen"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
Create your custom layout with all these attributes you've mentioned. Use Dialog instead of AlertDialog, inflate the layout you have created, use the Dialog object to set the inflated layout. If you haven't been introduced to inflating service, do some research. After you are clear with inflating, remember that all the components of the dialog you access with the View object, that you have created with the inflating. The rest (like click listeners) remains to be done on usual way. Cheers. I hope it helps.
To make custom AlertDialog you should extend DialogFragment

Android: dialog box without shadow around it

How do I remove this "shadowBox" effect around the dialog box that fades the background?
I know I can create like totally custom view but let's say I want to keep it simple. I have xml layout for dialog with only textView and 2 buttons and I want to stop the fade only for this one dialog.
Try:
dialog.getWindow().clearFlags(LayoutParams.FLAG_DIM_BEHIND);
create style.xml inside values and put things like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="progress_dialog">
<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">#00ffffff</item>
</style>
And in the end, put this style to your dialog box.
Simply use
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
here give the sample class
public void showDialog () {
Dialog dialog = new Dialog(this);
Window window = dialog.getWindow();
window.setBackgroundDrawableResource(android.R.color.transparent);
window.requestFeature(window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.sample);
ImageView imggameover, imgplayagain;
imggameover = (ImageView) dialog.findViewById(R.id.gameover);
imgplayagain = (ImageView) dialog.findViewById(R.id.playagain);
imgplayagain.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(getApplicationContext(), random.class));
onStop();
finish();
}
});
dialog.show();
}
Dialog's layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gameoverlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
>
<ImageView
android:id="#+id/gameover"
android:layout_width="225dip"
android:layout_height="160dip"
android:background="#drawable/gameover"
></ImageView>
<ImageView
android:id="#+id/playagain"
android:layout_width="160dip"
android:layout_height="wrap_content"
android:layout_marginLeft="100dip"
android:layout_marginTop="100dip"
android:background="#drawable/playagain"
></ImageView>
</RelativeLayout>
Just that you know it is also possible to change the dim amount by writing this in your theme:
<item name="android:backgroundDimAmount">0.5</item>

Categories

Resources