我读Custom dialog on Android: How can I center its title?但android不知道parent="@android:style/DialogWindowTitle
。Android,我如何在自定义对话框中更改标题的颜色?
我改变对话框样式:
<style name="customDialogStyle" parent="@android:style/Theme.Dialog">
<item name="android:gravity">center_horizontal</item>
<item name="android:textSize">25dip</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#04a9ee</item>
</style>
,并在代码中,我已经写了:
dialog = new Dialog(Inf_PackageActivity.this, R.style.customDialogStyle);
dialog.setTitle("Confirmation");
dialog.setContentView(R.layout.inf_dialoglayout);
每一件事情是确定的,我有我的自定义对话框。但我有一个问题: 我将style作为属性引入的背景色将填充所有对话框。我需要这种颜色只用于标题。 “R.layout.inf_dialoglayout” 的 XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dip"
android:layout_height="150dip"
android:orientation="vertical" >
<View
android:layout_width="wrap_content"
android:layout_height="3dp"
android:background="@drawable/separator" />
<TextView
android:text="Are you sure you want this package?"
style="@style/dialog.description"
android:paddingTop="10dip"
android:paddingBottom="13dip" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center" >
<Button
android:text="Yes!"
android:id="@+id/btnAccept"
android:background="@drawable/btngradient"
style="@style/ButtonText.Smaller" />
<Button
android:text="No!"
android:id="@+id/btnReject"
android:background="@drawable/btngradient"
style="@style/ButtonText.Smaller" />
</LinearLayout>
</LinearLayout>
最后应用的截图: 我在R.layout.inf_dialoglayout
感谢
更新定义的另一个背景颜色
你可以告诉我们的XML文件inf_dialoglayout –
嗨,我更新了这篇文章。 – Hesam
所以你想要你的确认字段来改变它的背景颜色或其他东西 –