获取AlertDialog的默认填充 [英] Getting default padding for AlertDialog

查看:99
本文介绍了获取AlertDialog的默认填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用自定义视图创建AlertDialog. AlertDialog的消息具有默认填充,但是当我设置一个视图时,它没有填充,因此我希望获得与该消息相同的默认填充.我使用的是扩展Holo主题的样式(如果相关).

I need to make a AlertDialog with a custom view. The message of a AlertDialog has a default padding but when i set a view it has no padding, i wand to get the same padding as the default as the message. I'm using a style that extends Holo theme (if this is relevant).

AlertDialog.Builder builder = new AlertDialog.Builder(PlaylistListView.this.getContext());
builder.setTitle("Title");
builder.setView(inflate(context, R.layout.music_player_create_dialog, null));
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();

这是内容的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/abc_dialog_padding_material"
    android:paddingRight="@dimen/abc_dialog_padding_material"
    android:paddingTop="@dimen/abc_dialog_padding_top_material"
    android:paddingBottom="@dimen/abc_dialog_padding_top_material">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Title:"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:background="@null"
        android:layout_marginTop="20dp"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:background="@color/divider"/>
</LinearLayout>

推荐答案

?dialogPreferredPadding属性现在具有此值.它是在API 22中引入的;参见 https://developer.android.com/sdk/api_diff/22/changes/android.R.attr.html .

The ?dialogPreferredPadding attribute now has this value. It was introduced in API 22; see https://developer.android.com/sdk/api_diff/22/changes/android.R.attr.html.

通过在对话框的布局上指定此属性,可以在自定义对话框中获得一致的填充.例如,android:paddingLeft="?dialogPreferredPadding"将使对话框的内容与其标题保持一致.

You can get consistent padding in your custom dialogs by specifying this attribute on the dialog's layout. For example, android:paddingLeft="?dialogPreferredPadding" will bring the dialog's contents into alignment with its title.

这篇关于获取AlertDialog的默认填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆