为了账号安全,请及时绑定邮箱和手机立即绑定

删除 AlertDialog 中项目顶部和底部的空格

删除 AlertDialog 中项目顶部和底部的空格

Smart猫小萌 2021-09-15 17:04:28
我有一个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);但没有占上风。我怎样才能删除这些边框?
查看完整描述

2 回答

?
慕桂英4014372

TA贡献1871条经验 获得超13个赞

删除:

android:padding="10dp"

In theTextView可能会有所帮助,因为TextView在您的情况下填充位于内容 ( ) 中。

如果它没有帮助,请尝试删除它:

<item name="android:padding">0dp</item>


查看完整回答
反对 回复 2021-09-15
  • 2 回答
  • 0 关注
  • 144 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信