Remove Black background from Alert Dialog Box - Android - android

I am working on an Android Application , Here I have created a custom dialog box , The dialog box was appearing on complete height of the device , but I wanted to leave margins from top and bottom , so I set margin using below code
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(alertDialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = Utility.convertDPtoPixel(400, screen);
alertDialog.show();
alertDialog.getWindow().setAttributes(lp);
Above code worked perfectly, but the dialog appears with black surroundings.
Here is the screen shot:
Now I want to remove these black surroundings from the dialog box.
Here is the code of dialog box:
public void showDialog() {
AlertDialog.Builder builder;
final AlertDialog alertDialog;
//final Dialog alertDialog;
Context mContext;
mContext = screen;
LayoutInflater inflater = (LayoutInflater) LoginActivity.screen.getSystemService(LoginActivity.screen.LAYOUT_INFLATER_SERVICE);
layout = inflater.inflate(R.layout.countrylist, null);
LinearLayout rellayout = (LinearLayout) layout.findViewById(R.id.rellayout);
RelativeLayout closeAcessCodeDialog = (RelativeLayout)layout.findViewById(R.id.closeAcessCodeDialog) ;
ListView listview = (ListView) layout.findViewById(R.id.listview);
listview.setAdapter(new CustomAdapter1(LoginActivity.screen, countryList));
builder = new AlertDialog.Builder(LoginActivity.screen);
builder.setView(layout);
alertDialog = builder.create();
alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(alertDialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = Utility.convertDPtoPixel(400, screen);
alertDialog.show();
alertDialog.getWindow().setAttributes(lp);
listview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int pos,
long id) {
countryName = idCountry.get(pos);
System.out.println("Country code is: " + countryName);
alertDialog.cancel();
text.setText(countryList.get(pos));
}
});
closeAcessCodeDialog.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
alertDialog.dismiss();
}
});
}
countrylist.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#ffe264"
app:cardCornerRadius="10dp"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rellayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_above="#+id/listview"
android:gravity="center_vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select your Country"
android:textColor="#000"
android:textSize="18sp"
android:textStyle="bold"
android:layout_centerInParent="true"
/>
<RelativeLayout
android:id="#+id/closeAcessCodeDialog"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:gravity="center">
<ImageButton
android:id="#+id/closeDialog"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/close_country_dialog" />
</RelativeLayout>
</RelativeLayout>
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#android:color/transparent"
android:divider="#e5e5e5"
android:background="#drawable/list_bacground"
android:dividerHeight="1px" />
</LinearLayout>
I visited many similar links over stackoverflow , but no one was helpfull .

Hope this will help you a lot
I think its default theme color which is Black so you have to check the import of your AlertDialog it should be import android.support.v7.app.AlertDialog; and one more thing you should use custom color for Background like below
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

Try this.
Dialog alertDialog = new Dialog(this);
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.setContentView(R.layout.yourlayout);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.show();

Related

Android Pop Up during opening of Application

I am developing an Android application, where I need to show a popup containing some message on application opening (Image attached for reference).
I have tried to achieve this using toast message and snack bar but could not do exact same.
Please suggest which component in Android to be used to achieve this functionality?
You can achieve the desired results using a dialog. I am sharing the code, you can modify it as you want but make sure you put it inside the onCreate method of the launcher activity.
This is the code for a simple dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Look at this dialog!")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do things
}
});
AlertDialog alert = builder.create();
alert.show();
The one shown in the picture shared by you is a custom dialog where you have to make your own layout. Here is an example,
1. Create your own layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff">
<ImageView
android:layout_width="match_parent"
android:layout_height="120dp"
android:id="#+id/a"
android:gravity="center"
android:background="#DA5F6A"
android:src="#drawable/dialog_cross"
android:scaleType="fitCenter" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEXT"
android:id="#+id/text_dialog"
android:layout_below="#+id/a"
android:layout_marginTop="20dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="20dp"
android:textSize="18sp"
android:textColor="#ff000000"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="OK"
android:id="#+id/btn_dialog"
android:gravity="center_vertical|center_horizontal"
android:layout_below="#+id/text_dialog"
android:layout_marginBottom="20dp"
android:background="#drawable/btn_flat_red_selector"
android:layout_centerHorizontal="true"
android:textColor="#ffffffff" />
</RelativeLayout>
2. Create a class for the custom dialog
public class ViewDialog {
public void showDialog(Activity activity, String msg){
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.dialog);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(msg);
Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog);
dialogButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
3. Make an object in your launcher activity of the custom dialog class and call the function showDialog
ViewDialog alert = new ViewDialog();
alert.showDialog(getActivity(), "Thank you for installing the Paytm
App");
Or you could use an external library for getting the desired results
Pop.on(this).with().title(R.string.title).layout(R.layout.custom_pop).show();
where R.layout.custom_pop is the custom layout of your dialog.
Try this for same result:
dialog.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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
<Button
android:id="#+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="X" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Hello, this is your message"
android:textSize="20sp" />
</LinearLayout>
code:
private void showDialog() {
final Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.dialog);
Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.BOTTOM;
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
dialog.findViewById(R.id.btnClose).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.cancel();
}
});
dialog.show();
}

How to remove title section from Dialog box in Android?

I want to remove title section from dialog box in Android and I want to use my own created xml file as Dialog box.
Inflate your XML. Like this
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
LayoutInflater inflater = context.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.yourlayout, null);
dialogBuilder.setView(dialogView);
AlertDialog b = dialogBuilder.create();
b.show();
You can inflate your own layout and set it to you Dialog.
Dialog dialog = new Dialog(ProfileSettingsActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.uploadphoto); // Your layout here
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT; //Custom width and height
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog.getWindow().setAttributes(lp);
dialog.setCancelable(true);
dialog.show();
Simply add style to dialog and remove title of the custom dialog.
Custom_dialog.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="wrap_content"
android:background="#color/colorPrimary"
android:orientation="vertical">
<TextView
android:id="#+id/txt_warning"`enter code here`
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Warning"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_dia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="Are you sure you want to Logout?"
android:textColor="#android:color/white"
android:textSize="18dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/btn_no"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight=".5"
android:background="#color/colorPrimary"
android:clickable="true"
android:gravity="center"
android:padding="10dp"
android:text="No"
android:textColor="#android:color/white"
android:textSize="18dp" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/white" />
<Button
android:id="#+id/btn_yes"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:background="#color/colorPrimary"
android:clickable="true"
android:gravity="center"
android:padding="10dp"
android:text="Yes"
android:textColor="#android:color/white"
android:textSize="18dp" />
</LinearLayout>
</LinearLayout>
Set style in Styles.xml:-
<style name="FullHeightDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
On button Click listener you have to write this code:-
// custom dialog
final Dialog dialog = new Dialog(mContext, R.style.FullHeightDialog);
dialog.setContentView(R.layout.custom_dialog);
dialog.setCancelable(false);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog.getWindow().setAttributes(lp);
dialog.show();
Button btnYes = (Button) dialog.findViewById(R.id.btn_yes);
Button btnNo = (Button) dialog.findViewById(R.id.btn_no);
// if button is clicked, close the custom dialog
btnYes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
documentImage = documentImagesList.get(getAdapterPosition());
//logout code here
}
});
btnNo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
Here is code for same:
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
LayoutInflater layoutInflater = getActivity().getLayoutInflater();
final ViewGroup viewGroup = null;
View dialogView = layoutInflater.inflate(R.layout.custom_email_dialog, viewGroup, false);
dialogBuilder.setView(dialogView);
final AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
Here is "custom_email_dialog" is custom XML that we need to show on dialog.
and you can access dialog element as:
TextView headerTextView = (TextView) dialogView.findViewById(R.id.emailHeader);

Android Custom AlertDialog not drawn correctly

I'm trying to customise the appearance of an AlertDialog. The problem is that I don't know how to get rid of the black lines that appear above my first TextView and EditText at the bottom (above the grey button regions).
Here is is my XML. What am I missing?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#color/butGreyBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="30"
android:text=""
android:background="#00000000"
android:textColor="#android:color/white"
android:textSize="22sp"
android:layout_margin="0dp"
android:gravity="center" />
<TextView
android:id="#+id/tv_prompt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="30"
android:text=""
android:background="#00000000"
android:textColor="#android:color/white"
android:textSize="18sp"
android:layout_margin="0dp"
android:gravity="center" />
<EditText
android:id="#+id/edit_text"
android:inputType="textCapSentences|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"/>
</LinearLayout>
Here's the code too - which is probably where the problem lies:
View alertView;
AlertDialog.Builder builder = new AlertDialog.Builder( mContext );
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
alertView = inflater.inflate(R.layout.alert_dialog_text, null);
builder.setView( alertView );
AlertDialog alertDialog = builder.create();
alertDialog.setView( alertView, 0,0,0,0 );
final EditText input = (EditText) alertView.findViewById( R.id.edit_text );
TextView tvTitle = (TextView) alertView.findViewById( R.id.tv_title );
TextView tvPrompt = (TextView) alertView.findViewById( R.id.tv_prompt );
tvTitle.setText( "Rename Playlist" );
tvPrompt.setText( "Enter new Playlist name." );
// Set up the buttons
builder.setPositiveButton( "OK", new DialogInterface.OnClickListener()
{
#Override
public void onClick( DialogInterface dialog, int which )
{
mNewName = input.getText().toString();
}
} );
builder.setNegativeButton( "Cancel", new DialogInterface.OnClickListener()
{
#Override
public void onClick( DialogInterface dialog, int which )
{
mNewName = "";
dialog.cancel();
}
} );
builder.show();
#sparky...
1) xml in Values Folder and add this code
wrap_content
wrap_content
#color/transparent1
false
true
and make a reference this Theme to Your Dialog Like this
Dialog dialog = new Dialog(activity, R.style.CustomDialogTheme);
then set Your custom Dialog Layout Xml file as setContentView.
dialog.setContentView(R.layout.customdialog);
2)you are not closing the parent LinearLayout at the end
and you are using #000000 color code for parent layout this will display black color at background
try to change the color code you bottom color will chance. and use
requestWindowFeature(Window.FEATURE_NO_TITLE);
in you dialog class this will remove the dialog title so your top color also will remove..
Let me know if you need any help
Thanks
I fixed this in the end by implementing my own custom dialog instead of using the AlertDialog.

Alert Box doesn't fit with screen in android

I'm using alert box, that doesn't fit to my device screen. Especially width, i can increase the height by adding empty view, but i couldn't increase width. It always have some empty space on left and right side.
I don't know exactly whether it is android's default property or re-sizable. I've also tried custom alert box but it doesn't work for me. This alert box will update progress and show until progress complete.
This my code:
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.sync_dialog, null);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity);
alertBuilder.setView(view);
alertBuilder.setCancelable(false);
AlertDialog progress = alertBuilder.create();
// Dialogs set their Window's top level layout width and height to WRAP_CONTENT.
// To make the Dialog bigger, you can set those parameters to FILL_PARENT.
progress.setCanceledOnTouchOutside(false);
progress.setCancelable(false);
progress.getWindow().getAttributes().width = LayoutParams.MATCH_PARENT;
progress.getWindow().getAttributes().height = LayoutParams.MATCH_PARENT;
mProgress = (ProgressBar) view.findViewById(R.id.progress);
/*Dialog dialog = new Dialog(activity, android.R.style.Theme_Translucent_NoTitleBar);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.sync_dialog);
dialog.setCanceledOnTouchOutside(false);
mProgress = (ProgressBar) view.findViewById(R.id.progress);*/
mText = (TextView) view.findViewById(R.id.message);
//Rebuilds ProgressBar with saved state when closed
if (!firstTime) {
mText.setText(mCurrentStatus);
mProgress.setProgress(mProgressStatus);
}
mProgress.setMax(mProgressMax);
return progress;
Layout File is:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="10dip" >
<ImageView
android:id = "#+id/btn_mfa_home"
android:src="#drawable/ic_mfa_icon_home"
android:layout_width="match_parent"
android:layout_height="fill_parent"
/>
<ImageView
android:id = "#+id/btn_sync_home"
android:src="#drawable/btn_sync_home"
android:paddingTop="50dp"
android:layout_width="match_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="12dip"
android:text="#string/dialog_initial_syncing"
android:textColor="#android:color/black" />
<ProgressBar
android:id="#+id/progress"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_gravity="center_horizontal"
android:layout_width="240dip"
android:layout_height="wrap_content"
android:max="100" />
</LinearLayout>
Any suggestions would be appreciated!
you are not setting the attrbutes on the dialog
something like this might help
AlertDialog.Builder adb = new AlertDialog.Builder(this);
Dialog d = adb.setView(new View(this)).create();
// (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
d.show();
d.getWindow().setAttributes(lp);
Note that the attributes are set after the Dialog is shown. The system is finicky about when they are set.
try using LayoutParams
mDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
I help, alone use it after yourAlertDialog.show()
alertDialog.show();
alertDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

How can I create my own theme for alertDialog?

I want to create a different theme for all of alertDialog instances. I need my own title view instead of the usual black title background. All text should have a blue color, and set the edge of the alertDialog to a round shape.
Is it possible to create our own theme for alert dialogs, using any style or creating a class which extends AlertDialog.Builder? I need a common theme or style for my all instances of alertDialog. I am using alertDialog in many places - one for singleChoice items, one with ArrayAdapter.
My alertDialog with array adapter:
String[] items = {"Edit profile","Change user","Change password","Logout"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Loged.this,
R.layout.my_spinner_layout, items);
settingMenu.setAdapter(adapter, listener);
My alertDialog with single choice items:
alertDelete = new AlertDialog.Builder(getParent());
alertDelete.setTitle("Delete");
alertDelete.setCancelable(true);
CharSequence[] choice = {"this user","All user"};
alertDelete.setSingleChoiceItems(choice, 0,
For my all alertDialog, I need a common theme, like:
please check this link. here am creating my own alertDialog class
and its a simple method if you reuse the alertDialog in many situation in your application
how Create setAdapter() for a AlertDialog
I solved my problem by creating a class which extends Dialog, and I created my own functions. for example setMessage,setTitle,setPositiveButton,setNegativeButton etc.
But am confusing on how we can replace the setAdapter() and setSingleChoice().
Here one example For Dialog:
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Give a Title...");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Put here any custom text!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
Button dialogButton = (Button) dialog.findViewById(R.id.ButtonOK);
// if button is clickedthen dialog will closed
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
Custom AlertDialog
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext;
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View urlayoutfile = inflater.inflate(R.layout.custom_dialog_xmlfile,(ViewGroup)findViewById(R.id.Yourlayout_id));
builder = new AlertDialog.Builder(this);
builder.setView(urlayoutfile);
alertDialog = builder.create();
alertDialog.show();
To use a specific style, use
ctw = new ContextThemeWrapper(this, R.style.MyStyle);
new AlertDialog.Builder(ctw)
.setTitle(...)
You can use layout as Different themes, styles, Backgrounds
customdialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
style="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/layoutsample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/dialoghdrbg"
android:orientation="horizontal" >
<ImageView
android:id="#+id/dialogheaderimage1"
android:layout_width="50dp"
android:layout_height="48dp"
android:scaleType="fitXY"
/>
<TextView
android:id="#+id/dialogheadertext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:layout_marginLeft="1dp"
android:gravity="center_vertical|right"
android:textColor="#000000"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/dialogcontentbg"
android:orientation="vertical" android:gravity="center">
<TextView
android:id="#+id/dialogmessgetext1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#ffffff"
android:textSize="23dp"
android:text=""
android:gravity="center"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:gravity="center|center_horizontal"
android:layout_marginTop="20dip"
android:orientation="horizontal">
<Button
android:id="#+id/dialogokbutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:background="#drawable/buttonanimation"
android:text="Retry"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="#+id/dialogcancelbutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonanimation"
android:text="Report"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
customDialog.java
final Dialog favDialog = new Dialog(Myclass.this,
android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
favDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
favDialog.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
favDialog.setContentView(R.layout.reloadurlpopuplayout);
favDialog.setCancelable(false);
ImageView dialogImage = (ImageView) favDialog
.findViewById(R.id.dialogheaderimage1);
dialogImage.setBackgroundResource(R.drawable.questionmark);
TextView dialogMesage = (TextView ) favDialog
.findViewById(R.id.dialogmessgetext1);
TextView dialogHeader = (TextView) favDialog
.findViewById(R.id.dialogheadertext1);
String descText = getString(R.string.RetryReportMessage);
dialogMesage.setBackgroundColor(0x00000000);
dialogMesage.setText(descText);
dialogHeader.setText(R.string.BrockenLinkHeader);
try {
favDialog.show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Categories

Resources