我有一个AlertDialog
由ArrayAdapter
. 当我显示 时AlertDialog
,项目的顶部和底部都有空格。我想完全删除它们。当然,更改AlertDialog
背景颜色以匹配项目的背景可以解决问题,但我想将其完全删除。这是所说的空间:
这是 AlertDialog 的样式:(colorPrimaryLight 是空格的颜色)
<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>
用于 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>
我使用的代码:
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();
我尝试使用:
AlertDialog dialog = b.show();
dialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
但没有占上风。
我怎样才能删除这些边框?
慕桂英4014372
相关分类