【发布时间】:2018-11-04 21:02:55
【问题描述】:
我有一个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);
但没有占上风。
如何去除这些边框?
【问题讨论】:
-
请尝试将边距也设置为 0 )
-
可以显示 layout.template_textview 文件吗?
-
你的
template_textview.xml可能有边距或内边距 -
@Tepits 我没用过。
标签: java android android-alertdialog