By default, spacers for custom layout in the Material dialog box

I am using appcompat-v7 AlertDialog and the Google Material Design lib:

compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'

I created DialogFragmentone that creates my dialog using a custom layout:

// import android.support.v7.app.AlertDialog;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());

    final ViewGroup v = (ViewGroup) LayoutInflater.from(dialogBuilder.getContext()).inflate(R.layout.d_password, null);

    final AlertDialog dialog = dialogBuilder.setTitle("Pass")
        .setView(v)
        .setPositiveButton(android.R.string.ok, null)
        .setNegativeButton(android.R.string.cancel, null)
        .create();

    return dialog;
}

My layout is d_password.xmlas follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/et_pass"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Pass"
            android:inputType="textPassword" />
    </android.support.design.widget.TextInputLayout>
</LinearLayout>

The problem is that there is no layout in the layout - it almost comes into contact with the title and the right / left dialog box.

To make it look like a standard materials dialog (with text instead of a custom layout), I had to change the layout:

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

The question is: how can I set up my own default layout if you do not repeat it every time in the layout?

+4
1

. .

, . , .

styles.xml

<style name="YourTheme.MaterialMargins" parent="ParentTheme">
        <item name="android:paddingLeft">@dimen/abc_dialog_padding_material</item>
        <item name="android:paddingRight">@dimen/abc_dialog_padding_material</item>
        <item name="android:paddingTop">@dimen/abc_dialog_padding_top_material</item>
</style>

YourTheme MaterialMargins.

XML , .

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    style="@style/YourTheme.MaterialMargins">

, layout_width layout_height, .

+1

All Articles