[英]Android AlertDialog - Header background color
我正在嘗試更改AlertDialog的“標題”(頂部)的背景顏色。 我設法改變標題的顏色,但我找不到你如何改變其容器的背景顏色。 可能嗎? 有什么建議?
這就是我到目前為止所擁有的。
AndroidManifest.xml中
<application
...
android:theme="@style/AppTheme">
styles.xml
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
<item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
</style>
another_file_with_styles.xml
<style name="AlertDialogTheme" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:textColor">@color/success_color</item>
</style>
類中的方法可以做到這一點
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(searchCriteria.getName());
builder.setItems(items, clickListener);
AlertDialog alert = builder.create();
alert.show();
// Eventually I'll do this to change the color of the divider
// int titleDividerId = context.getResources().getIdentifier("titleDivider", "id", "android");
// View titleDivider = alert.findViewById(titleDividerId);
//
// if (titleDivider != null) {
// titleDivider.setBackgroundColor(context.getResources().getColor(R.color.accent_color));
//}
我試圖按照本教程 ,但它沒有解釋如何更改窗口的背景顏色。
編輯:只是為了清楚,箭頭指向灰色/白色背景顏色(不是標題[制造和模型])
您可以使用自定義標題視圖設置標題的背景顏色。
創建自定義標題視圖並定義背景顏色:
res / layout / custom_title.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor"
android:padding="16dp">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/textColor" />
</RelativeLayout>
設置自定義標題視圖:
View customTitleView = getLayoutInflater().inflate(R.layout.custom_title, null);
TextView title = (TextView) customTitleView.findViewById(R.id.title);
title.setText("TITLE");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setItems(items, clickListener);
builder.setCustomTitle(customTitleView);
AlertDialog alert = builder.create();
alert.show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.