首页 > 代码库 > 2种方法自定义对话框
2种方法自定义对话框
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种方法自定义对话框
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。