自定义AlertDialog
来源:互联网 发布:c语言程序员工资 编辑:程序博客网 时间:2024/06/05 16:44
dialog_exit_order.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/shape_transform" android:orientation="vertical" android:paddingTop="16dp" > <TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="回撤原因" android:textColor="#000" android:textSize="18sp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginTop="16dp" android:background="#000" /> <RadioGroup android:id="@+id/rg" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="6dp" android:orientation="vertical" android:paddingLeft="11dp" android:paddingRight="11dp" > <RadioButton android:id="@+id/rb0" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:button="@null" android:checked="true" android:drawableRight="@drawable/radiobutton_selector" android:paddingLeft="6dp" android:text=" " android:textColor="@drawable/color_redio_button" android:textSize="16sp" android:visibility="gone" /> <RadioButton android:id="@+id/rb1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:button="@null" android:drawableRight="@drawable/radiobutton_selector" android:paddingLeft="6dp" android:text=" " android:textColor="@drawable/color_redio_button" android:textSize="16sp" android:visibility="gone" /> <RadioButton android:id="@+id/rb2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:button="@null" android:drawableRight="@drawable/radiobutton_selector" android:paddingLeft="6dp" android:text=" " android:textColor="@drawable/color_redio_button" android:textSize="16sp" android:visibility="gone" /> <RadioButton android:id="@+id/rb3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:button="@null" android:drawableRight="@drawable/radiobutton_selector" android:paddingLeft="6dp" android:text=" " android:textColor="@drawable/color_redio_button" android:textSize="16sp" android:visibility="gone" /> <RadioButton android:id="@+id/rb4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:button="@null" android:drawableRight="@drawable/radiobutton_selector" android:paddingLeft="6dp" android:text=" " android:textColor="@drawable/color_redio_button" android:textSize="16sp" android:visibility="gone" /> <RadioButton android:id="@+id/rb5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:button="@null" android:drawableRight="@drawable/radiobutton_selector" android:paddingLeft="6dp" android:text=" " android:textColor="@drawable/color_redio_button" android:textSize="16sp" android:visibility="gone" /> <RadioButton android:id="@+id/rb6" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:button="@null" android:drawableRight="@drawable/radiobutton_selector" android:paddingLeft="6dp" android:text=" " android:textColor="@drawable/color_redio_button" android:textSize="16sp" android:visibility="gone" /> </RadioGroup> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:orientation="horizontal" android:paddingLeft="11dp" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="备注:" android:textColor="#000" android:textSize="16sp" /> <RelativeLayout android:layout_width="220dp" android:layout_height="wrap_content" > <EditText android:id="@+id/et_input" android:layout_width="180dp" android:layout_height="wrap_content" android:background="#0000" android:cursorVisible="false" android:hint=" " android:textColor="#000" android:textSize="13sp" /> <View android:layout_width="180dp" android:layout_height="0.5dp" android:layout_below="@id/et_input" android:background="#000" /> </RelativeLayout> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginTop="16dp" android:background="#000" /> <LinearLayout android:layout_width="match_parent" android:layout_height="48dp" android:orientation="horizontal" > <TextView android:id="@+id/ok" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="确定" android:textColor="#2196f3" android:textSize="16sp" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#000" /> <TextView android:id="@+id/cancel" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="取消" android:textColor="#2196f3" android:textSize="16sp" /> </LinearLayout></LinearLayout>
ExitOrderDialog
package com.clt.runman.widget;import java.util.List;import android.R.integer;import android.app.AlertDialog;import android.content.Context;import android.os.Bundle;import android.text.Editable;import android.text.TextWatcher;import android.view.LayoutInflater;import android.view.View;import android.widget.EditText;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Toast;import android.widget.RadioGroup.OnCheckedChangeListener;import android.widget.TextView;import com.clt.runman.R;public class ExitOrderDialog extends AlertDialog { private Context ctx; private View customView; private List<String> info; private EditText eText; private RadioGroup rg; private RadioButton rb0; private RadioButton rb1; private RadioButton rb2; private RadioButton rb3; private RadioButton rb4; private RadioButton rb5; private RadioButton rb6; private int checkedId = R.id.rb0; private String message = ""; public ExitOrderDialog(Context context, List<String> info) { super(context); this.ctx = context; this.info = info; LayoutInflater inflater = LayoutInflater.from(context); customView = inflater.inflate(R.layout.dialog_exit_order, null); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(customView); eText = (EditText) customView.findViewById(R.id.et_input); rg=(RadioGroup)findViewById(R.id.rg); rb0=(RadioButton)findViewById(R.id.rb0); rb1=(RadioButton)findViewById(R.id.rb1); rb2=(RadioButton)findViewById(R.id.rb2); rb3=(RadioButton)findViewById(R.id.rb3); rb4=(RadioButton)findViewById(R.id.rb4); rb5=(RadioButton)findViewById(R.id.rb5); rb6=(RadioButton)findViewById(R.id.rb6); initRadioGroup(); TextView cancel = (TextView) customView.findViewById(R.id.cancel); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 隐藏当前对话框 dismiss(); } }); TextView ok = (TextView) customView.findViewById(R.id.ok); ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO 待做任务 提交相应的操作 switch (checkedId) { case R.id.rb0: message = info.get(0); break; case R.id.rb1: message = info.get(1); break; case R.id.rb2: message = info.get(2); break; case R.id.rb3: message = info.get(3); break; case R.id.rb4: message = info.get(4); break; case R.id.rb5: message = info.get(5); break; case R.id.rb6: message = info.get(6); break; } Toast.makeText(ctx, "信息:" + message + inputString, Toast.LENGTH_LONG).show(); // 隐藏当前对话框 dismiss(); } }); } String inputString = ""; /** * 初始化RadioG *@Description: (这里用一句话描述这个方法的作用) *@Author: 郭永振 *@Since: 2016-12-16下午5:15:26 */ private void initRadioGroup() { // 初始化radioButon for (int i = 0; i < info.size(); i++) { RadioButton rb = (RadioButton) rg.getChildAt(i); rb.setVisibility(View.VISIBLE); rb.setText(info.get(i)); } rg.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId1) { checkedId = checkedId1; } }); eText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { eText.setCursorVisible(true); } }); eText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { inputString = s.toString(); } }); } @Override public View findViewById(int id) { return super.findViewById(id); } public View getCustomView() { return customView; } }
shape_transform.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:bottomLeftRadius="3dp" android:bottomRightRadius="3dp" android:topLeftRadius="3dp" android:topRightRadius="3dp" > </corners> <solid android:color="#fefefe" > </solid></shape>
radiobutton_selector.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/checked_1" android:state_checked="true"/> <item android:drawable="@drawable/unchecked_1" android:state_checked="false"/></selector>
展示弹出框的方法
public void exitOrder(View view) { List<String> messages = new ArrayList<String>(); messages.add("1.临时有事,预约到其他时间"); messages.add("2.操作错误"); messages.add("3.其他"); // 弹出警告提示框 提示需要选择的回撤订单的原因// Toast.makeText(this, "点击了订单回撤按钮", Toast.LENGTH_LONG).show(); ExitOrderDialog dialog = new ExitOrderDialog(this, messages); dialog.show(); // 将对话框的大小按屏幕大小的百分比设置 WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); lp.width = (int)(display.getWidth() * 0.8); //设置宽度 dialog.getWindow().setAttributes(lp); }
1 0
- 自定义 alertDialog
- 自定义AlertDialog
- AlertDialog自定义
- 自定义AlertDialog
- 自定义 AlertDialog
- 自定义AlertDialog
- 自定义Alertdialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- AlertDialog 自定义
- 自定义AlertDialog
- 自定义alertDialog
- 优秀博客搜集
- mysql-5.7.17-winx64免安装版环境配置 问题小记
- 智邦交换机在hybrid模式下license更新
- PAT编程基础 5-9 用天平找小球 (10分)
- apache优化
- 自定义AlertDialog
- 一个经典例子让你彻彻底底理解java回调机制
- 网卡队列 irq绑定
- 《React-Native系列》43、通用容器和导航设计方案
- 你还在做仰卧起坐吗?
- 一致性非锁定读与一致性锁定读
- Linux 下清空或删除大文件内容的5中方法
- 二叉查找树<链表实现>
- 【MongoDb探究】01-mongodb是神马