上運作效果圖
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsICdzFWRoRXdvN1LclHdpZXYyd2LcBzNvwVZ2x2bzNXak9CX90TQNNkRrFlQKBTSvwFbslmZvwFMwQzLcVmepNHdu9mZvwFVywUNMZTY18CX052bm9CX9cGVOd3ZU5UMVpWT4VkalZXUYpVd1kmYr50MZV3YyI2cKJDT29GRjBjUIF2LcRHelR3LcJzLctmch1mclRXY39jN1EDNyETNyETNyMDM0EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
下面是4個圓角設定:
這裡設定圓角主要是項目需求隻要這樣,需要根據你自己的需求去改一個圖檔什麼都行
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
</shape>
下面是布局頁面的設定:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/dialog_style"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/dialog_textview_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center"
android:text="資訊"
android:textSize="12sp" />
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="@android:color/black" />
<TextView
android:id="@+id/dialog_textview_ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center"
android:text="确定"
android:textSize="15sp" />
</LinearLayout>
接着是MainActivity頁面使用:
View view = LayoutInflater.from(HomeQuestionActivity.this).inflate(R.layout.dialog, null);
TextView tv_text = (TextView) view.findViewById(R.id.dialog_textview_text);
tv_text.setText("已經是最後一題了");
AlertDialog.Builder builder = new AlertDialog.Builder(HomeQuestionActivity.this);
final AlertDialog dialog = builder.setView(view).create();
dialog.show();
view.findViewById(R.id.dialog_textview_ok).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
參考資料:http://www.oschina.net/question/563014_70928 點選打開連結