自定義的Dialog

在activity須要彈框時便可調用自定義的dialog 以下: android

 MoveDialog mRemoveDialog = new MoveDialog(this);
   mRemoveDialog.setOnScreenChangeListener(mOnMoveDialogClickListener);
   mRemoveDialog.showMoveDialog(); ide

須要如今activity中 佈局

private OnMoveDialogClickListener mOnMoveDialogClickListener this

 = new OnMoveDialogClickListener() {doing()} spa

//Dialog類 .net

public class MoveDialog { 
 private Context context;
 private  Button btnOk,btnCancel;
 private Dialog dialog;
 private OnMoveDialogClickListener onDialogClickListener;
 public void setOnScreenChangeListener(OnMoveDialogClickListener onDialogClickListener) {
  this.onDialogClickListener = onDialogClickListener;
 }
 
 public MoveDialog(Context context) {
  this.context = context;
 }
 
 public  void showMoveDialog(){
  dialog = new Dialog(context, R.style.removedialog);
  dialog.setContentView(R.layout.remove_dialog);
  TextView title = (TextView) dialog.findViewById(R.id.title);
  btnOk = (Button)dialog.findViewById(R.id.btnok);
  btnCancel = (Button)dialog.findViewById(R.id.btncancel);
  btnOk.requestFocus();
  btnOk.setOnClickListener(mClicklistener);
  btnCancel.setOnClickListener(mClicklistener);
  dialog.show();
 }
 
 private OnClickListener mClicklistener = new OnClickListener() { 
  @Override
  public void onClick(View v) {
   if(v == btnOk){
    if(onDialogClickListener !=null)
     onDialogClickListener.onButtonClick();
    dialog.dismiss();
   }else if(v ==btnCancel){
    dialog.dismiss();
   }} };} xml

//dialog樣式  接口

<style name="removedialog" parent="@android :style/Theme.Dialog">
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:backgroundDimEnabled">false</item>
  <item name="android:windowBackground">@android :color/transparent</item>
    </style> rem

 

//佈局 get

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="328dp"
    android:layout_height="107dp"
 android:background="@drawable/remove_dialog_bg">
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="15dp"
        android:text="@string/removetitle"
        android:textColor="@color/white"
        android:textSize="20dp" />
    <RelativeLayout
        android:id="@+id/bt_bottom"
        android:layout_width="fill_parent"
        android:layout_height="55dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp" >
        <Button
            android:id="@+id/btnok"
            android:layout_width="164dp"
            android:layout_height="55dp"
            android:gravity="center"
            android:text="@string/btnyes"
            android:textSize="20dp" />
        <Button
            android:id="@+id/btncancel"
            android:layout_width="164dp"
            android:layout_height="55dp"
            android:layout_alignParentRight="true"
            android:gravity="center"
            android:text="@string/btnno"
            android:textSize="20dp" />
    </RelativeLayout>
</RelativeLayout>

 

//接口

public class interfaces {  public interface OnAddListener{      void addAction(int addPostion);  }  public interface OnMoveDialogClickListener {   void onButtonClick();  }}

相關文章
相關標籤/搜索