Change Dialog title background color

Asked

Viewed 847 times

0

I have the following dialog box:

Dialog

The green part was mounted with a LinearLayout, but the attribute android:background="#77FF77" did not change the titlebar color.

Java da Dialog:

public void ver_log(View v){
   DialogLog();
}

private void DialogLog(){
    final Dialog dialogLog = new Dialog(this);
    dialogLog.setContentView(R.layout.dialog_log);

    dialogLog.setTitle("CÁLCULOS");

    final Button btnFechar = (Button) dialogLog.findViewById(R.id.btn_fechar);
    final Button btnCopiar = (Button) dialogLog.findViewById(R.id.btn_copiar);

    btnFechar.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialogLog.dismiss();
        }
    });

    btnCopiar.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //Ação de copiar
        }
    });

    dialogLog.show();
}

XML of the Dialog:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    style="@style/Dialogs" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp">

    <TextView
        android:id="@+id/relatorio"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="" />

    </LinearLayout>

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <Button
            style="@style/BotoesDialogs"
            android:id="@+id/btn_fechar"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="@string/fechar" />
        <Button
            style="@style/BotoesDialogs"
            android:id="@+id/btn_copiar"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="@string/copiar" />
    </LinearLayout>

</LinearLayout>

How can I change that part? It would also be possible to change the color of the title "CALCULUS" and this blue bar below?

  • 2

    You have two ways, or write the style’s of Dialog in your theme. Or remove the title (using requestWindowFeature(Window.FEATURE_NO_TITLE) in the onCreate, before anything) and creates a custom title for the Dialog, within the layout of your content Dialog.

  • 1

    While this does not answer your question, it may help you: https://github.com/inmite/android-styled-dialogs

  • It worked, @Wakim. I used requestWindowFeature(Window.FEATURE_NO_TITLE) placing just above the layout definition of the Dialog. Thank you!

1 answer

1


You have two ways:

Or overwrite the style’s Dialog every app in your theme.

Or remove the title using the Dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) in the onCreate, before anything. And create a custom title for Dialog, within the layout of your content Dialog

Browser other questions tagged

You are not signed in. Login or sign up in order to post.