Android AlertDialog标题背景颜色 [英] Android AlertDialog title background color
本文介绍了Android AlertDialog标题背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以更改AlertDialog(android.support.v7.app.AlertDialog)的标题背景颜色?目前,在我的主题中,我有
Is there any way to change the title background color of AlertDialog (android.support.v7.app.AlertDialog)?? Currently in my theme I have
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/colorAccent</item>
</style>
我正在得到它,
如何使它看起来像这样
使用
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTitleStyle">@style/DialogTitle</item>
</style>
<style name="DialogTitle">
<item name="android:background">@color/colorPrimary</item>
</style>
给予
关于如何实现此目标的任何想法?
Any ideas on how this can be accomplished?
推荐答案
您可以这样设置自定义标题
You can just set custom title like this
LayoutInflater inflater = this.getLayoutInflater();
View titleView = inflater.inflate(R.layout.custom_title, null);
new AlertDialog.Builder(SubCategoryActivity.this)
.setCustomTitle(titleView);
并且在custom_title布局中,您可以创建这样的自定义标题
and in custom_title layout you can create custom title like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:id="@+id/llsubhead"
android:background="@color/colorPrimary">
<TextView
android:id="@+id/exemptionSubHeading4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:text="Exemption Sub Head"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
这篇关于Android AlertDialog标题背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文