Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
why Android dialog title not showing on android versions marshmallow?

I was trying to create a custom dialog here is my code :

        val myDialog = Dialog(this)
        myDialog.setContentView(R.layout.my_dialog)
        myDialog.setTitle("My Dialog!")
        myDialog.setCancelable(true)
        myDialog.show()

Here is my_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<TextView
        android:text="Hello world!"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:textSize="30sp"/>

</android.support.constraint.ConstraintLayout>

I have run this on android version lollipop It works fine here is screenshot on lollipop :

Dialog on Android version Lollipop

as you can see dialog title is showing but when I try to run this on Android version marshmallow title stop showing here is screenshot on marshmallow :

Dialog on android version marshmallow

as you can see dialog title not showing on android version marshmallow. I have try adding this line for showing title :

myDialog.create()

but title still not showing. what should I do?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Have you tried applying custom style... The dialog adopts the Style of the parent Activity which might have been set to NoTitle.

<style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog">
    <item name="android:windowNoTitle">false</item>
</style>

On the java code

new AlertDialog.Builder(new ContextThemeWrapper(Context, R.style.Dialog))
over 4 years ago · Santiago Trujillo Relatório

0

Use AlertDialog instead of Dialog.

  AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle(getString(R.string.app_name));
        alertDialogBuilder.setMessage(getString(R.string.disclaimer))
                .setCancelable(false)
                .setPositiveButton("Ok",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                            }
                        });
        AlertDialog alert = alertDialogBuilder.create();
        alert.show();
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda