Reputation: 323
I want to make my AlertDialog transparent, the following is my code and the line where it should be transparent just doesnt work.
AlertDialog.Builder builder;
AlertDialog alertDialog;
context = getActivity();
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.moreinfotable,null);
ListView list = (ListView) layout.findViewById(R.id.dialog_listView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
ViewImage.this.getActivity(), R.layout.interior_listview,
R.id.interior_list_text, values);
list.setAdapter(adapter);
builder = new AlertDialog.Builder(context);
builder.setView(layout);
alertDialog = builder.create();
//THE LINE THAT DOESNT WORK// alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.show();
can someone please help. Thank you.
This is what i want to do.
Upvotes: 0
Views: 2337
Reputation: 821
Use this way
alertDialog.show();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.argb(0, 200, 200, 200)));
I did this on custom alert dialog.
Values are like alpha, red, green, blue. Range from 0 to 255. Change values of alpha to get different degree of transparency
I don't know if this will help you. This is how i created my dialog box (its a prompt to user to try the app without log-in)
public void promptUser()
{
final Dialog requestDialog= new Dialog(MyActivity.this);
requestDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
requestDialog.setContentView(R.layout.lyt_prompt_user);
TextView requestTitle = (TextView) requestDialog.findViewById(R.id.request_title);
TextView requestText = (TextView) requestDialog.findViewById(R.id.request_text);
Button acceptButton = (Button) requestDialog.findViewById(R.id.request_accept);
Button rejectButton = (Button) requestDialog.findViewById(R.id.request_reject);
requestTitle.setText("Don't want to login?");
requestText.setText("You can still explore the app with limited functionality.");
acceptButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// do something
requestDialog.dismiss();
finish();
startActivity(intent);
}
});
rejectButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
requestDialog.dismiss();
(MyActivity.this).finish();
}
});
requestDialog.setCancelable(false);
requestDialog.show();
requestDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.argb(0, 200, 200, 200)));
}
I tried changing the alpha from 0 to 90, it shows a faint white background, somewhat glassy feeling.
Upvotes: 4