1调用部分
public class RenameDialog {
private Context context;
public RenameDialog(Context context){
this.context = context;
}
public void showExitsDialog() {
final Dialog dialog = new Dialog(context); //, R.style.dialog);
// 取得自定义View
LayoutInflater layoutInflater = LayoutInflater.from(context);
View unlinkOKLayout = layoutInflater.inflate(R.layout.mydialogly, null);
Button okButton = (Button) unlinkOKLayout.findViewById(R.id.btnOk);
Button cancelButton = (Button) unlinkOKLayout.findViewById(R.id.btnCancel);
dialog.setContentView(unlinkOKLayout);
dialog.show();
dialog.setCanceledOnTouchOutside(true);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
}
}
2 xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320dp"
android:layout_height="480dp"
android:background="#3FFF2FdF"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="320dp"
android:layout_height="38dp" >
<TextView
android:id="@+id/titleId"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:gravity="center"
android:text="设置频道" />
</RelativeLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="4dp"
android:background="#FF0A9DCD"
/>
<RelativeLayout
android:layout_width="320dp"
android:layout_height="396dp" >
</RelativeLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="4dp"
android:background="#FF0A9DCD" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="320dp"
android:layout_height="38dp" >
<Button
android:layout_width="159dp"
android:layout_height="match_parent"
android:id="@+id/btnOk"
android:background="#3c000000"
android:text="Ok"/>
<TextView android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#3c000000"/>
<Button
android:layout_width="159dp"
android:layout_height="match_parent"
android:id="@+id/btnCancel"
android:background="#3c000000"
android:text="Cancel"/>
</LinearLayout>
</LinearLayout>
以上是简单的一个例子,在继续研究如何自定义AlertDialog的Theme,目前还没有进展先做这些了。