android - 使用自定义view的 alert dialog
访问量: 2038
参考: https://stackoverflow.com/questions/2795300/how-to-implement-a-custom-alertdialog-view
1. 添加xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/verify_failed_dialog" android:layout_width="match_parent" android:layout_height="253dp" android:orientation="vertical" android:layout_marginLeft="40dp" android:layout_marginRight="40dp" android:background="#f8f8f8" android:layout_centerInParent="true" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/verify_failed" android:textAlignment="center" android:textSize="22sp" android:textColor="#030303" android:layout_marginTop="20dp" /> </LinearLayout>
2. 在对应Activity的方法中,添加:
LayoutInflater inflater = getLayoutInflater(); View dialoglayout = inflater.inflate(R.layout.verify_failed_dialog, null); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(dialoglayout); builder.show();