自定义Dialog
(1)自定义布局文件
<LinearLayout xmlns:android="http://schmas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/closed"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:background="@drawable/btn_closed" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dip"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开台"
android:background="@drawable/btn_closed" />
<Button
android:id="@+id/detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="详情"
android:background="@drawable/btn_closed" />
</LinearLayout>
</LinearLayout>
(2)自定义Dialog类
public class MyDialog extends Dialog implements android.view.View.OnClickListener{
private Context context;
private Button isClosed;
private Button order;
private Button detail;
private Map<String,Object> map;
public void setMap(Map<String,Object> map){
this.map=map;
}
public MyDialog(Context context,boolean cancelable,OnCancelListener cancelListener){
super(context,cancelable,cancelListener);
}
public MyDialog(Context context,int theme){
this.context=context;
}
public MyDialog(Context context){
this.context=context;
}
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.myDialog);
isClosed=(Button)findViewById(R.id.closed);
order=(Button)findViewById(R.id.order);
detail=(Button)findViewById(R.id.detail);
isClosed.setOnClickListener(this);
order.setOnClickListener(this);
detail.setOnClickListener(this);
}
@Override
public void onClick(View v){
switch(v.getId()){
case R.id.closed:
this.dismiss();
break;
case R.id.detail:
DetailTableDialog detailDialog=new DetailTableDialog(context,R.style.MyDialog);
Window win=detailDialog.getWindow();
LayoutParams params=new LayoutParams();
params.x=-200;
params.y=-100;
win.setAttributes(params);
detailDialog.setCanceledOnTouchOutside(false);
detailDialog.setMap(map);
detailDialog.show();
break;
case R.id.order:
Intent intent=new Intent(context,OrderActivity.class);
Bundle bundle=new Bundle();
SerializableMap mapSer=new SerializableMap();
bundle.putSerializable("map",mapSer);
intent.putExtras(bundle);
context.startActivity(intent);
this.dismiss();
break;
default:
break;
}
}
}
(3)调用Dialog
MyDialog myDialog=new MyDialog(context,R.style.MyDialog);
myDialog.setMap(list.get(position));
myDialog.setCanceledOnTouchOutside(false);
myDialog.show();
(4)MyDialog的Styles.xml
<style name="MyDialog" parent="@android:Theme.Dialog">
<item name="android.windowFrame">@null</item>
<item name="android.windowNoTitle">true</item>
<item name="android.windowBackground">@android:color/transparent</item>
<item name="android.windowIsFloating">true</item>
<item name="android.windowContentOverlay">@null</item>
</style >