【发布时间】: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"/>
【问题讨论】: