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

我有一个AlertDialogArrayAdapter. 当我显示 时AlertDialog,项目的顶部和底部都有空格。我想完全删除它们。当然,更改AlertDialog背景颜色以匹配项目的背景可以解决问题,但我想将其完全删除。这是所说的空间:

http://img1.mukewang.com/6141b733000111c607161263.jpg

这是 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);

但没有占上风。


我怎样才能删除这些边框?


Smart猫小萌
浏览 145回答 2
2回答

慕桂英4014372

删除:android:padding="10dp"In theTextView可能会有所帮助,因为TextView在您的情况下填充位于内容 (&nbsp;) 中。如果它没有帮助,请尝试删除它:<item&nbsp;name="android:padding">0dp</item>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java