final alertdialog dialog = new alertdialog.builder(context).create();
dialog.show();
window window = dialog.getwindow();
window.setwindowanimations(r.style.dialogwindowanim);//設定對話方塊顯示和消失動畫
window.setlayout((int) context.getresources().getdimension(100dp,100dp));//設定對話方塊的大小
window.setbackgrounddrawableresource(r.drawable.tanchuangbeijing);//設定對話方塊的背景
layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);
view view = inflater.inflate(r.layout.dialog_prompt, null);
textview tvdesc = (textview) view.findviewbyid(r.id.tv_desc);
if (!textutils.isempty(text))
button btnpositive = (button) view.findviewbyid(r.id.btn_positive);
button btnnegative = (button) view.findviewbyid(r.id.btn_negative);
btnpositive.setonclicklistener(new view.onclicklistener()
}});
btnnegative.setonclicklistener(new view.onclicklistener()
});
//預設顯示在視窗的正中間,但是可以通過x改變水平位置,y改變垂直位置,x為正向右偏移,反之向左偏移,y為正向下偏移,反之向上;
windowmanager.layoutparams attributes = window.getattributes();
attributes.x = x;
attributes.y = y;
window.setattributes(attributes);
window.setcontentview(view);
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...