Reputation: 3212
I have a custom layout in my AlertDialog
which has a ListView
inside. Now I want to remove the black background of the AlertDialog
.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.rate_card_layout, null);
Button close = (Button) dialogView.findViewById(R.id.btnClose);
close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
ListView lv = (ListView)dialogView.findViewById(R.id.listView1);
RateListAdapter rLAdapter = new RateListAdapter(SActivity.this,
listItemsArray);
lv.setAdapter(rLAdapter);
builder.setView(dialogView);
final Dialog dialog = builder.create();
dialog.show();
I tried adding
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
as usual. But that isn't working.
Any help will be greatly appreciated.
Upvotes: 1
Views: 701
Reputation: 3319
Try This
Add custom dialog style in style.xml
<style name="DialogTheme" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
In Activity
Dialog dialog = new Dialog(this, R.style.DialogTheme);
OR
AlertDialog.Builder builder=new AlertDialog.Builder(this,R.style.DialogTheme);
Upvotes: 0
Reputation: 471
Try using this to customise your theme. Also Declare AlertDialogCustom iin styles
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
And then style it like you want:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">10sp</item>
............. //background etc
</style>
</resources>
Upvotes: 0
Reputation: 4328
Try
private void updateLayoutParams() {
Window window = getDialog().getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.dimAmount = 0.2f;
int margin = getResources().getInteger(R.integer.common_margin);
DisplayMetrics metrics = new DisplayMetrics();
((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
params.width = metrics.widthPixels-margin;
window.setAttributes(params);
window.setBackgroundDrawableResource(android.R.color.transparent);
getDialog().setCanceledOnTouchOutside(false);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.d(TAG, "onConfigurationChanged");
updateLayoutParams();
}
Upvotes: 1