Sense Wide
article thumbnail

Changing Text Color of AlertDialog List item

(setItems로 등록된 list item의 text color 바꾸기)



 One of the easiest and fastest way to customizing AlertDialog into material design is to put R.style file in the builder as following.


Java file


AlertDialog.Builder builder = new AlertDialog.Builder(A4_MakeScheduleActivity.this, R.style.myDialogStyle);


Xml file (styles.xml)


<style name="myDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#FFCC00</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:background">#03A9F4</item>
</style>




 Here, for the easier way to put items (options), I used the method "setItems" to the builder like following.


final CharSequence[] items = {"Camera", "Gallery"};


builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (item == 0) {

} else {

}

}

};


But the problem was that it only appears black item text color like below.





 So, I looked through many questions and answers but not clear solution for this. But, finally i found there is a straightforward attributes to the styles.xml file.

 You, just need to attach the attribute "textColorAlertDialogListItem" as shown below.


<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#FFCC00</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="textColorAlertDialogListItem">#FFFFFF</item>
<item name="android:background">#03A9F4</item>
</style>



 note that not android:textColorAlertDialogListItem but without android:.


 So it's working now.







Result



  




profile

Sense Wide

@June_Kim

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!