【问题标题】:Style AlertDialog Submit Button and Title样式 AlertDialog 提交按钮和标题
【发布时间】:2016-02-12 05:32:05
【问题描述】:

我正在设计我的AlertDialog。我已经成功地设置了背景(看它的蓝色)和单选项目(看它们是白色和橙色文本)的样式。

是否可以设置AlertDialog 标题背景、页脚提交按钮和页脚背景的样式?有关以红色突出显示的这些区域,请参见下图。 是否可以使AlertDialog 具有圆角矩形角?

如您所见,我可以将标题标签背景颜色设置为蓝色,但不能将整个标题背景设置为蓝色?

实施:

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(mActivity, R.style.AlertDialogCustom));
builder.setTitle("Select");

ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
        getActivity(), R.layout.choices, choices);
builder.setSingleChoiceItems(adapter, -1, myOnClickListener);


// Styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
        <item name="android:textColor">#00FF00</item>
        <item name="android:textSize">10sp</item>
        <item name="android:background">#0000ff</item>
        <item name="android:fontFamily">fonts/myCustomFont.ttf</item>
    </style>
</resources>


// choices.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:fontFamily="fonts/myCustomFont.ttf"
    android:textColor="@color/theme_orange"
    android:gravity="center_vertical"
    android:ellipsize="marquee"
    android:text="Text"
    android:background="#fff"
    android:paddingLeft="16dip"
    android:paddingRight="7dip"/>

【问题讨论】:

    标签: java android


    【解决方案1】:

    您可以使用自定义布局(xml 文件)来代替它并在那里添加您的所有要求。 然后将该视图设置为您的对话框:

    builder.setView(R.layout.custom_view);
    

    也不要忘记删除上面提到的标题here

    【讨论】:

      【解决方案2】:

      在此链接中,我展示了如何设置 AlertDialog 提交按钮和标题的样式。它还展示了如何自定义 AletDialog。例如,如何更改分隔线颜色等。请访问此链接:

      https://stackoverflow.com/a/33439849/5475941

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 2011-08-09
        • 1970-01-01
        • 2010-09-25
        • 1970-01-01
        • 1970-01-01
        • 2016-05-13
        • 2013-02-15
        • 2011-09-16
        • 1970-01-01
        相关资源
        最近更新 更多