简体   繁体   English

如何在android中更改警告对话框的WindowTitle?

[英]How to change the WindowTitle of alert dialog in android?

Anyone knows how to change the window title text color and other styles of an alert dialog popped up when you click a list item in preference activity? 任何人都知道如何在首选项活动中单击列表项时更改窗口标题文本颜色和弹出的警报对话框的其他样式?

I have changed the background but text isn't changing. 我改变了背景,但文字没有改变。 I'll paste my style code here. 我会在这里粘贴我的样式代码。

<style name="alertDialogThemeLight" parent="@android:style/Theme.Dialog">
       <item name="android:background">#ffaaaaaa</item>
       <item name="android:windowTitleStyle">@style/dialogTitleLight</item>
</style>

<style name="dialogTitleLight">
        <item name="android:textSize">12sp</item>
        <item name="android:textColor">#ff0000</item>
       <!-- <item name="android:textAppearance">@style/dialogTitleTextLight</item> -->
</style>

<style name="dialogTitleTextLight">
        <item name="android:textColor">#334455</item>
        <item name="android:textSize">30dp</item>
</style>

I can't find attribute to change text color. 我找不到改变文字颜色的属性。

您可以更改<item name="android:textColor">#ff0000</item>#ff0000 - 这是颜色代码,您需要更改它

<item name="android:background">#ffaaaaaa</item>, this is doesn't correct, after "#" only be  6 charakters

Try this, It will replace the title of your alert dialog 试试这个,它将取代警报对话框的标题

Create a separate Layout and place textView in that, Apply styles for it in the xml file. 创建一个单独的布局并将textView放入其中,在xml文件中为其应用样式。 Then add that view in this below method : 然后在以下方法中添加该视图:

alertDialogObj.setCustomTitle(View);

For Your Reference : Click this Link 供您参考:单击此链接

You can get the object AlertDialog.Builder. 您可以获取对象AlertDialog.Builder。

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        //set message, title, and icon
        builder.SetTitle("Title");
        builder.SetMessage("Some Question?");

        //set twooption buttons
        builder.SetPositiveButton("Yes", new EventHandler<DialogClickEventArgs>(OnExitDialogClicked));
        builder.SetNegativeButton("No", new EventHandler<DialogClickEventArgs>(OnExitDialogClicked));
        AlertDialog dialog = builder.Create();

        TextView tv = new TextView(dialog.Context);
        tv.Text = "Text";

        dialog.SetCustomTitle(tv);

        dialog.Show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM