}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class DialogWidget extends Dialog {
Activity activity;
private View view;
private boolean isOutSideTouch = true;
public View getView() {
return view;
}
public void setView(View view) {
this.view = view;
}
public boolean isOutSideTouch() {
return isOutSideTouch;
}
public void setOutSideTouch(boolean isOutSideTouch) {
this.isOutSideTouch = isOutSideTouch;
}
public DialogWidget(Context context, int theme) {
super(context, theme);
}
public DialogWidget(Context context) {
super(context, 0);
// TODO Auto-generated constructor stub
}
public DialogWidget( Activity activity, View view ) {
super(activity, R.style.MyDialog);
this.activity = activity;
this.view = view;
}
public DialogWidget( Activity activity,View view,int theme){
super(activity,theme);
this.activity = activity;
this.view = view;
}
public DialogWidget( Activity activity,View view,int theme,boolean isOutSide ){
super(activity,theme);
this.activity = activity;
this.view = view;
this.isOutSideTouch = isOutSide;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(view);
setCanceledOnTouchOutside( isOutSideTouch );
DisplayMetrics dm = new DisplayMetrics();//手机屏幕大小
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();
layoutParams.width = screenWidth;
layoutParams.height = screenHeight-60;
this.getWindow().setAttributes( layoutParams );
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Activity中进行引用
dialogWidget = new DialogWidget(KeyPayPwdActivity.this, getKeyPayView());
dialogWidget.show();
}
private View getKeyPayView() {
// TODO Auto-generated method stub
return KeyPayPasswordView.getInstance(null, KeyPayPwdActivity.this, new OnPayListener() {
@Override
public void onSurePay(String password) {
// TODO Auto-generated method stub
openOnepayServiceReq( password );
}
@Override
public void onSuccess(Context context) {
// TODO Auto-generated method stub
}
@Override
public void onCancelPay() {
// TODO Auto-generated method stub
dialogWidget.dismiss();
KeyPayPwdActivity.this.finish();
}
}).getView();
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
keypaypwd.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
tools:context="com.zryf.sotpicbcnew.KeyPayPwdActivity" >
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/dyq_keyboard"
android:layout_margin="8dp"
android:background="@drawable/edittext_bg_nor"
android:orientation="vertical" >
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/pay_title"
android:textColor="#404040"
android:textSize="16sp" />
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="8dp"
android:background="#e1dfdf" />
android:layout_height="wrap_content" >
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="@string/pay_pwd_txt" />
android:layout_height="40dp"
android:layout_margin="4dp"
android:background="@drawable/sex_box_bg"
android:orientation="horizontal" >
style="@style/InputTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="match_parent"
android:background="@drawable/sex_boxline_bg" />
style="@style/InputTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="match_parent"
android:background="@drawable/sex_boxline_bg" />
style="@style/InputTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="match_parent"
android:background="@drawable/sex_boxline_bg" />
style="@style/InputTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="match_parent"
android:background="@drawable/sex_boxline_bg" />
style="@style/InputTextView"
android:layout_width="0dp"
android:maxLength="1"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="match_parent"
android:background="@drawable/sex_boxline_bg" />
style="@style/InputTextView"
android:maxLength="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="@string/action_settings" />
android:layout_height="40dp"
android:layout_margin="4dp"
android:background="@drawable/sex_box_bg"
android:orientation="horizontal" >
style="@style/InputTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="match_parent"
android:background="@drawable/sex_boxline_bg" />
style="@style/InputTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="match_parent"
android:background="@drawable/sex_boxline_bg" />
style="@style/InputTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="match_parent"
android:background="@drawable/sex_boxline_bg" />
style="@style/InputTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="match_parent"
android:background="@drawable/sex_boxline_bg" />
style="@style/InputTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="match_parent"
android:background="@drawable/sex_boxline_bg" />
style="@style/InputTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_height="1dp"
android:layout_margin="8dp"
android:background="#e1dfdf" />
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/pay_cancel"
android:textColor="#404040"
android:textSize="16sp" />
android:layout_height="fill_parent"
android:background="@drawable/sex_boxline_bg" />
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/dyq_pay_sure"
android:textColor="#404040"
android:textSize="16sp" />
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="40dp"
android:background="#CFCFCF"
android:orientation="vertical" >
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:background="@drawable/keyboard_one_selector"
android:contentDescription="@string/action_settings" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="@drawable/keyboard_two_selector"
android:contentDescription="@string/action_settings" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:background="@drawable/keyboard_three_selector"
android:contentDescription="@string/action_settings" />
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:background="@drawable/keyboard_four_selector"
android:contentDescription="@string/action_settings" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="@drawable/keyboard_five_selector"
android:contentDescription="@string/action_settings" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:background="@drawable/keyboard_sex_selector"
android:contentDescription="@string/action_settings" />
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:background="@drawable/keyboard_seven_selector"
android:contentDescription="@string/action_settings" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="@drawable/keyboard_eight_selector"
android:contentDescription="@string/action_settings" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:background="@drawable/keyboard_nine_selector"
android:contentDescription="@string/action_settings" />
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/keyboard_space"
android:contentDescription="@string/action_settings" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/keyboard_zero_selector"
android:contentDescription="@string/action_settings" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/keyboard_del_selector"
android:contentDescription="@string/action_settings" />
以上是根据仿支付宝支付的事例进行修改后的样子。之所以修改是因为在经过自己反复测试生,发现存在一个问题:就是当连续的打开密码框Dialog时,会出现有输入不上密码的情况,事件也不会触发。最后发现,原来的KeyPayPasswordView中自定义的数字键盘所触发的是单击事件,后来改为onTouch事件后发现不会有这种情况发生。可又出现了新的问题,就是点击数字时背景不会变化,呃。。真是烦呢!
后来,又经过网上查看,发现onTouch事件与onLongClick事件间的一点关联,根据onTouch返回的值确定何时触发onLongClick事件,所以又给数字键加入了onLongClick事件后,完美解决了上述问题。真是技术不牛,累死人的节奏呀。
目前这个事例效果良好,没有发现其他bug,如果有大神看出破绽请提点。。