I have an AlertDialog
with items provided by ArrayAdapter
. When I show the AlertDialog
, there are spaces on top and bottom of the items. I want to remove them completely. Sure, changing the color of AlertDialog
background to match the item's background would do the trick but I want to remove it completely. This is the said spaces:
This is the style for AlertDialog: (colorPrimaryLight is the spaces' color)
<style name="style_alert_dialog" parent="Theme.AppCompat.Dialog.Alert">
<item name="android:padding">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:background">@color/colorPrimaryLight</item>
</style>
Layout used for ArrayAdapter (template_alert_dialog_item):
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorTextWhite"
android:background="@color/colorPrimaryNormal"
android:textSize="15sp"
android:padding="10dp">
</TextView>
Code I used:
ArrayAdapter<String> adapter = new ArrayAdapter<>(ReviewMeTooMainPage.this, R.layout.template_alert_dialog_item,
getResources().getStringArray(R.array.menu_items));
AlertDialog.Builder b = new Builder(ReviewMeTooMainPage.this, R.style.style_alert_dialog);
View inflatedTemplate = getLayoutInflater().inflate(R.layout.template_textview,(
ViewGroup) findViewById(R.id.main_page_display),false);
TextView textView = inflatedTemplate.findViewById(R.id.template_title);
b.setCustomTitle(textView);
b.setAdapter(adapter, new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
b.show();
I tried to use:
AlertDialog dialog = b.show();
dialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
but no prevail.
How can I remove those borders?