1.首先在资源里面建立style的value;
[html] view
plaincopy
<!-- ShareDialog -->
<style name="Theme.ShareDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/fill_box</item>
<item name="android:windowNoTitle">true</item>
</style>
2.drawable/filled_box.xml:
[html] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<shape>
<stroke android:width="3dp" />
<corners android:radius="3dp" />
<padding android:left="10dp" android:top="10dp" android:right="10dp"
android:bottom="10dp" />
</shape>
<item android:drawable="@drawable/dialog_my_bg" />
</selector>
3.方法:
[java] view
plaincopy
public static Dialog getDialog(final Context context, final String name) {
final Dialog dialog = new Dialog(context, R.style.Theme_ShareDialog);
dialog.setContentView(R.layout.dialog_share_comment);
Button btnshare = (Button) dialog.findViewById(R.id.dialog_btn_ok);
btnshare.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
}
});
return dialog;
}
其中 dialog.setContentView(R.layout.dialog_share_comment);是对话框的布局
new Dialog(context, R.style.Theme_ShareDialog);引用style
4.调用
[java] view
plaincopy
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.