自定義 對話方塊類:
public class alertdialogui
if (!ad.isshowing())
// 關鍵在下面的兩行,使用window.setcontentview,替換整個對話方塊視窗的布局
// window window = ad.getwindow();
// window.setcontentview(r.layout.alertdialog);
view layout = inflater.inflate(r.layout.alertdialog, null);
window dialogwindow = ad.getwindow();
displaymetrics metrics = new displaymetrics();
((activity) context).getwindowmanager().getdefaultdisplay()
.getmetrics(metrics);
int width = (int) ((metrics.widthpixels) * 0.8);
windowmanager.layoutparams layoutparams = ad.getwindow()
.getattributes();
layoutparams.width = width;
dialogwindow.setattributes(layoutparams);
ad.setcontentview(layout, new linearlayout.layoutparams(
linearlayout.layoutparams.wrap_content,
linearlayout.layoutparams.wrap_content));
titleview = (textview) layout.findviewbyid(r.id.title);
messageview = (textview) layout.findviewbyid(r.id.message);
btn_sure = (textview) layout.findviewbyid(r.id.btn_sure);
btn_cancle = (textview) layout.findviewbyid(r.id.btn_cancle);
} catch (exception e)
}public void showdialog()
}public void setdismisslistener()
public void settitle(int resid)
public void settitle(string title)
public void setmessage(int resid)
public void setmessage(string message)
public void setcanceledontouchoutside(boolean flag)
public void setcancleable(boolean flag)
/*** 設定按鈕
* * @param text
* @param listener
*/public void setpositivebutton(string text,
final view.onclicklistener listener)
/*** 設定按鈕
* * @param text
* @param listener
*/public void setnegativebutton(string text,
final view.onclicklistener listener)
/*** 關閉對話方塊
*/public void dismiss() catch (exception e)
}}
布局檔案layout: alertdialog
<?xml version="1.0" encoding="utf-8"?>
資源檔案ui_new_dialog_common_normal
<?xml version="1.0" encoding="utf-8"?>
ui_new_dialog_common_pressed
<?xml version="1.0" encoding="utf-8"?>
-end android 自定義對話方塊
說到對話方塊你肯定會想到alertdialog.builder。當然這次不是用alertdialog.builder來實現的!而是dialog類 alertdialog.builder提供的方法有 settitle 給對話方塊設定title.seticon 給對話方塊設定圖示。setmessage ...
android自定義對話方塊
效果圖 主要 package cn.bzu.dialogcase import android.os.bundle import android.content.dialoginte ce import android.view.layoutinflater import android.view....
Android自定義對話方塊
android提供的對話方塊常常不能滿足專案需求,所以我們需要自定義更美觀適用的對話方塊。1.自定義alertdialog 效果 自定義alertdialog的類 package com.example.showdialog import android.content.context import...