AlertDialog 텍스트 내용 수정 색상
final CheckBox cb = new CheckBox(this);
cb.setChecked(false);
cb.setText(getResources().getString(R.string.close_wifi_switch));
dialog = new AlertDialog.Builder(this)
.setTitle(getResources().getString(R.string.exit_wimo_sure))
.setView(cb)
.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
// Do nothing.
}
})
.setPositiveButton(R.string.exit,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
}).create();
dialog.show();
그러므로 반사법으로 AlertDialog의 title 색상 값을 읽고 이를 CheckBox의 Text Color에 부여할 수 있는지 생각한 후에 인터넷에서 관련 Alert Controller 클래스를 찾았다. 이 클래스는 AlertDialog의 실현 클래스로 외부에 공개되지 않았다. 그리고 이 클래스에 개인 구성원 변수가 mTitle View라고 있는데 이것이 바로 AlertDialog의 title Text View이다. 그래서 이 구성원 변수의 실례를 얻으면타이틀의 색상 값을 얻을 수 있습니다
dialog.show();// ,
try {
Field mAlert = AlertDialog.class.getDeclaredField("mAlert");
mAlert.setAccessible(true);
Object alertController = mAlert.get(dialog);
Field mTitleView = alertController.getClass().getDeclaredField(
"mTitleView");
mTitleView.setAccessible(true);
TextView title = (TextView) mTitleView.get(alertController);
ColorStateList colorStateList = title.getTextColors();
cb.setTextColor(colorStateList);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
checkBox의 Text 색상을 수정하는 것과 유사하며, AlertDialog의 title 글꼴 색상, title를 직접 수정할 수도 있습니다.setTextColor(XXXXX)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Flutter AlertDialog의 너비를 화면 가득 늘립니다.AlertDialog의 너비를 화면 가득 늘리고 싶습니다. 원래는 통상의 화면이었던 것을, 다이얼로그화해 주었으면 한다고 말해져, 다이얼로그화했지만, 아무래도 비좁은 느낌이 되어 버리고 있었으므로, 다이얼로그의 패딩...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.