修改AlertDialog 按鈕的背景

2021-07-12 05:06:08 字數 661 閱讀 3836

alertdialog 提供了下面的方法來獲取button物件:

public button getbutton (int whichbutton)

added in api level 3

gets one of the buttons used in the dialog.

if a button does not exist in the dialog, null will be returned.

parameters

whichbutton the identifier of the button that should be returned. for example, this can be button_positive.

returns

the button from the dialog, or null if a button does not exist.

獲取button物件後,就可以對button進行操作了。這裡注意,必須在alertdialog.show()之後才能通過 getbutton 獲取到button物件,否則返回為null。

參考:

AlertDialog的樣式修改

一 控制dialog 的背景方法 1.定義乙個無背景主題主題 2.建立dialog dialog new dialog this,r.style.dialog dialog.setcontentview r.layout.dialog loading or dialog new dialog thi...

修改AlertDialog的大小

最近做的專案中使用到了alertdialog,需要調節alertdialog的大小,試了好多方法,終於成功了,記錄一下 dialog.getwindow setlayout 460,140 這個方法一定要寫在show 後面才會成功。下面的做法也可以,不過同樣要在show後面做。windowmanag...

修改按鈕的樣式

修改按鈕的樣式 有過程式設計經歷的都知道,vs 2008預設生成的按鈕在編輯狀態下的樣式還看得順眼,但執行時的外觀就不堪入目了,跟windows 98的主題差不多,很死板。我們能不能修改一下按鈕的外觀呢?答案是肯定的。下面我們就共同 下修改按鈕樣式的方法。修改按鈕樣式的實質其實就是用位圖資源替代普通...