Android, как я могу изменить цвет заголовка в моем диалоговом окне? - PullRequest
2 голосов
/ 01 декабря 2011

Я читаю Пользовательский диалог на 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

спасибо

Обновление: XML-файл "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>

и, наконец, снимок экрана приложения: enter image description here

1 Ответ

0 голосов
/ 01 декабря 2011

Вы можете попробовать с этим XML, я изменил немного 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" >

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dip"
android:layout_height="150dip"
android:orientation="vertical" 
android:background=" colou u want here in ur title " >

<View
    android:layout_width="wrap_content"
    android:layout_height="3dp"
    android:background="@drawable/separator" />

</LinearLayout>

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dip"
android:layout_height="150dip"
android:orientation="vertical" >
<TextView 
    android:text="Are you sure you want this package?" 
    style="@style/dialog.description"
    android:paddingTop="10dip"
    android:paddingBottom="13dip" />
</LinearLayout>

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dip"
android:layout_height="150dip"
android:orientation="vertical" >
<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>
</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...