码迷,mamicode.com
首页 > 其他好文 > 详细

2种方法自定义对话框

时间:2015-01-15 16:05:17      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:对话框   dialog   

1:全部布局自定义

                LayoutInflater addBlackNumberInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
                View view = addBlackNumberInflater.inflate(R.layout.alert_dialog_disagree_refund, null);
                final AlertDialog.Builder reasonBuilder = new AlertDialog.Builder(SaleOrderDetailActivity.this);
                reasonBuilder.setView(view);
                final Dialog dialog = reasonBuilder.create();
                dialog.show();
                final EditText editText = (EditText) view.findViewById(R.id.edit_reason);
                Button cancelBT = (Button) view.findViewById(R.id.btn_cancel);
                Button confirmBT = (Button) view.findViewById(R.id.btn_confirm);
                confirmBT.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ToastUtil.show(SaleOrderDetailActivity.this, editText.getText().toString());
                    }
                });

                cancelBT.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });


alert_dialog_disagree_refund.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:gravity="center"
              android:background="@color/white">

    <TextView
        style="@style/LightGreyColor.LargeFont"
        android:layout_width="fill_parent"
        android:padding="@dimen/padding_medium"
        android:gravity="center"
        android:textColor="@color/cinnamomum"
        android:text="@string/refund_disagree"/>

    <View
        style="@style/BaseStyle.Line.Divier"
        android:background="@color/black"/>

    <EditText
        style="@style/LightGreyColor.LargeFont"
        android:paddingBottom="@dimen/margin_xxxlarge"
        android:paddingTop="@dimen/margin_xxxlarge"
        android:minLines="2"
        android:textColor="@color/text_title"
        android:layout_width="fill_parent"
        android:gravity="center"
        android:id="@+id/edit_reason"
        android:hint="@string/refund_disagree_reason"/>

    <View
        style="@style/BaseStyle.Line.Divier"
        />

    <LinearLayout
        style="@style/BaseStyle.FullWrap"
        android:id="@+id/btn_layout"
        android:orientation="horizontal">

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:background="@color/white"
            android:paddingTop="@dimen/margin_large"
            android:paddingBottom="@dimen/margin_large"
            android:layout_weight="1"
            android:id="@+id/btn_cancel"
            android:textColor="@color/title_color"
            android:text="取消"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:paddingTop="@dimen/margin_large"
            android:paddingBottom="@dimen/margin_large"
            android:layout_weight="1"
            android:id="@+id/btn_confirm"
            android:background="@color/background_button_brown"
            android:textColor="@color/white"
            android:text="确定"/>
    </LinearLayout>

</LinearLayout>

技术分享



2:部分布局自定义

View container = getLayoutInflater().inflate(R.layout.dialog_input, null);
                final EditText inputET = (EditText) container.findViewById(R.id.et_input);
                new AlertDialog.Builder(this).setTitle("出价购买").setView(container).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String s = inputET.getText().toString().trim();
                        ToastUtil.show(SaleOrderDetailActivity.this, s);
                }).setNegativeButton(android.R.string.cancel, null).create().show();

dialog_input.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    style="@style/Rosemary.Line.Light"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="@dimen/margin_standard">

    <EditText
        android:id="@+id/et_input"
        style="@style/Rosemary.Line"
        android:maxLength="10"
        android:numeric="integer">

        <requestFocus/>
    </EditText>
</FrameLayout>






2种方法自定义对话框

标签:对话框   dialog   

原文地址:http://blog.csdn.net/pengkv/article/details/42741693

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!