自定義對話框

下面是顯示自定義對話框的代碼

    private void showDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(Blackname_Activity.this);
        //要自定義對話框的樣式所以調用creat方法
        AlertDialog dialog = builder.create();
        View view = View.inflate(getApplicationContext(), R.layout.blackname_insert_dialog, null);
        //將低版本的間距取消掉
        dialog.setView(view,0,0,0,0);
        dialog.show();
    }

剛開始我把

AlertDialog.Builder builder = new AlertDialog.Builder(Blackname_Activity.this);
寫成了
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());

報了個錯誤

Unable to add window -- token null is not for an application
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容