Android,如何更改自定义对话框中标题的颜色?
我读过 Android 上的自定义对话框:如何将其居中标题? 但 android 不知道 parent="@android:style/DialogWindowTitle
。
我将对话框样式更改为:
<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);
一切都很好,我有我的自定义对话框,但我有一个问题: 我在样式中作为属性引入的背景颜色将填充所有对话框。我需要这种颜色只在标题中使用。我在 R.layout.inf_dialoglayout
中定义了另一种背景颜色,
谢谢
更新: “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>
最后是应用程序的屏幕截图:
I read Custom dialog on Android: How can I center its title? but android doesn't know parent="@android:style/DialogWindowTitle
.
I changed dialog style to:
<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>
and in code i have written:
dialog = new Dialog(Inf_PackageActivity.this, R.style.customDialogStyle);
dialog.setTitle("Confirmation");
dialog.setContentView(R.layout.inf_dialoglayout);
Every thing is ok and i have my custom dialog. but i have an issues:
The background color that I introduce in style as an attribute will fill all the dialog. I need this color just be used in Header. I have defined another background color in R.layout.inf_dialoglayout
thanks
Update:
XML file of "R.layout.inf_dialoglayout":
<?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>
and finally Screenshot of app:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以尝试使用这个 xml 我已经改变了一点 xml
You can try with this xml i have changed the xml little bit