AlertDialog styling - how to change style (color) of title, message, etc

前端 未结 8 1435
醉梦人生
醉梦人生 2020-12-04 14:31

I\'ve breaking my head over this quite a bit. What I need to do is, change the style of all AlertDialogs in my android application - dialog background needs to

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 14:52

    I changed color programmatically in this way :

    var builder = new AlertDialog.Builder (this);
    ...
    ...
    ...
    var dialog = builder.Show ();
    int textColorId = Resources.GetIdentifier ("alertTitle", "id", "android");
    TextView textColor = dialog.FindViewById (textColorId);
    textColor?.SetTextColor (Color.DarkRed);
    

    as alertTitle, you can change other data by this way (next example is for titleDivider):

    int titleDividerId = Resources.GetIdentifier ("titleDivider", "id", "android");
    View titleDivider = dialog.FindViewById (titleDividerId);
    titleDivider?.SetBackgroundColor (Color.Red);
    

    this is in C#, but in java it is the same.

提交回复
热议问题