這絕對有可能,實際上你可以隨心所欲地做任何事情。真的,其中一個選擇是使用風格和主題,但在4.x中不起作用。可以說,適當或簡單的方法是使用視圖本身,如下所示:
// we need this listener since only here all views are really drawn and accessible
yourDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
if (isButtonsFixed)
return;
// both buttons - you could search for only positive button or whatever button your dialog has
final Button btnPositive = getButton(DatePickerDialog.BUTTON_POSITIVE);
final Button btnNegative = getButton(DatePickerDialog.BUTTON_NEGATIVE);
final Button btnNeutral = getButton(DatePickerDialog.BUTTON_NEUTRAL);
// buttons layout parameters, change it into material style (gravity right)
final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) btnPositive.getLayoutParams();
lp.weight = 0; // was 1 to fill 50% horizontally
// positive button, set your own label
btnPositive.setText(R.string.dialog_ok_label);
// set text color and size
btnPositive.setTextColor(ResHelper.getColor(R.color.blue_bright));
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, ResHelper.getDimensPx(R.dimen.text_size_14));
btnPositive.setLayoutParams(lp);
// divider above buttons
((LinearLayout) btnPositive.getParent().getParent()).setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
}
這(最後一行)將刪除按鈕上方的分隔符。如果你想定製它,而不是像下面這樣:
((LinearLayout) btnPositive.getParent().getParent()).setDividerDrawable(R.drawable.yer_drawable);
只是爲了確認,即使我可以在編程運行時做到這一點? 我覺得我無法找到如何訪問該組件。 無論如何,我會嘗試做一個主題到一天,並確認結果,非常感謝:D – Kanit 2014-08-29 15:35:46
@Kanit接受這個答案,如果沒關係;) – Sidd 2015-04-14 14:46:13