2016-03-01 4 views
4

Я пытаюсь изменить цвет фона «заголовка» (верхней части) AlertDialog. Мне удалось изменить цвет заголовка, но я не могу найти, как вы меняете цвет фона своего контейнера. Является ли это возможным? Какие-либо предложения?Android 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)); 
//} 

Я пытался следовать this tutorial, но это не объясняет, как изменить цвет фона окна.

EDIT: просто быть ясно, стрелка указывает на серый/белый цвет фона (не на название [Марка и модель])

enter image description here

+0

Scroll немного в уроке, который вы опубликовали. ** Часть 5: стиль фона ** Я хочу красный фон за моим названием. – beeb

ответ

1

Вы можете установить цвет фона с использованием пользовательского заголовка.

Creat зрения пользовательского заголовка и определить цвет фона:

Рез/макет/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(); 
Смежные вопросы