Android Dialog: Removing title bar

AndroidLayoutDialog

Android Problem Overview


I have a weird behavior I can't pinpoint the source of.

I have my app with the classic

requestWindowFeature(Window.FEATURE_NO_TITLE);

to remove the title/status bar.

I then create a Dialog box to allow the user to enter information (name etc)

With a physical keyboard, no problem but when I use the virtual keyboard I have a strange behavior:

each time I hit a key on the virtual key board the title/status bar reappears pushing all the keyboard layout around then vanishes again (just like the animation of when I start the application)

here is some code :

		dialog = new Dialog(context);
		dialog.setContentView(R.layout.logindialog);
		dialog.setTitle("Login:");

		WindowManager.LayoutParams a = dialog.getWindow().getAttributes();

//		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		a.dimAmount = 0;
		dialog.getWindow().setAttributes(a);
		
		dialog.setCancelable(true);
		dialog.getWindow().setLayout(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);

and then

dialog.show();

I tried

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

but it crashes my app.

here is the xml

http://schemas.android.com/apk/res/android" android:id="@+id/test" android:gravity="center_horizontal" android:orientation="vertical" android:layout_alignParentTop="true" android:layout_width="fill_parent" android:layout_height="wrap_content">

	<TextView android:id="@+id/LoginText"
		android:gravity="fill"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="Login:">
	</TextView>     	
	<EditText android:id="@+id/LoginEdit"
		android:layout_height="wrap_content"
		android:singleLine="true"
		android:text="jason"
		android:layout_width="200sp"/>
	<TextView android:id="@+id/PasswordText"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="Password:">
	</TextView>     	
	<EditText android:id="@+id/PasswordEdit"
		android:layout_height="wrap_content"
		android:singleLine="true"
		android:text="welcome"
		android:layout_width="200sp"
		android:password="true"/>
<LinearLayout 
	android:id="@+id/test2"
	android:gravity="center_horizontal"
	android:orientation="horizontal"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content">
<Button android:id="@+id/LoginButton"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_centerHorizontal="true"
	android:text="Login" />
<Button android:id="@+id/CreateButton"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_centerHorizontal="true"
	android:text="Create" />
<Button android:id="@+id/CancelLogin"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_centerHorizontal="true"
	android:text="Cancel" />
</LinearLayout>/>

Android Solutions


Solution 1 - Android

use,

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before     
dialog.setContentView(R.layout.logindialog);

Solution 2 - Android

create new style in styles.xml

<style name="myDialog" parent="android:style/Theme.Dialog">
   <item name="android:windowNoTitle">true</item>
</style>

then add this to your manifest:

 <activity android:name=".youractivity" android:theme="@style/myDialog"></activity>

Solution 3 - Android

All the above answer not working for me for AppCompatDialog

If you are using AppCompatDialog try this

Important note: Set this before calling setContentView.

> dialog.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

Solution 4 - Android

create your XML which is shown in dialog here it is activity_no_title_dialog

final Dialog dialog1 = new Dialog(context);
dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog1.setContentView(R.layout.activity_no_title_dialog);
dialog1.show();

Solution 5 - Android

With next variant I have no reaction:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before     
dialog.setContentView(R.layout.logindialog);

So, I try to use next:

dialog.supportRequestWindowFeature(Window.FEATURE_NO_TITLE); //before     
dialog.setContentView(R.layout.logindialog);

This variant work excellent.

Solution 6 - Android

You can also define Theme in android manifest file for not display Title bar..

You just define theme android:theme="@android:style/Theme.Light.NoTitleBar" in activity where u dont want to display title bar

Example:-

http://schemas.android.com/apk/res/android" android:versionCode="3" android:versionName="1.2" package="xyz">

    <uses-sdk android:minSdkVersion="4"android:targetSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".splash"
              android:label="@string/app_name" android:screenOrientation="portrait"
              android:theme="@android:style/Theme.Light.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

<activity android:name="main" android:screenOrientation="portrait" android:theme="@android:style/Theme.Light.NoTitleBar"></activity>

Solution 7 - Android

if you are using a custom view then remeber to request window feature before adding content view like this

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.show();

Solution 8 - Android

use below code before setcontentview :-

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
dialog.setContentView(R.layout.custom_dialog);

Note:- above code must have to use above dialog.setContentView(R.layout.custom_dialog);

In XML use a theme

android:theme="@android:style/Theme.NoTitleBar"

also styles.xml:

<style name="hidetitle" parent="android:style/Theme.Dialog">
   <item name="android:windowNoTitle">true</item>
</style>

And then:

Dialog dialog_hidetitle_example = new Dialog(context, R.style.hidetitle);

Solution 9 - Android

I am an Android novice and came across this question trying to get rid of a title bar.

I'm using an activity and displaying it as a dialog. I was poking around with themes and came across a useful bit of default theming.

Here's the code from my AndroidManifest.xml that I was using when the title bar was showing:

<activity
    android:name=".AlertDialog"
    android:theme="@android:style/Theme.Holo.Dialog"

    >

</activity>

Here's the change that got me my desired result:

<activity
    android:name=".AlertDialog"
    android:theme="@android:style/Theme.Holo.Dialog.NoActionBar"

    >

</activity>

As I said, I'm still new to Android, so this may have undesirable side-effects, but it appears to have given me the outcome I wanted, which was just to remove the title bar from the dialog.

Solution 10 - Android

I'm using next variant:

Activity of my custom Dialog:

public class AlertDialogue extends AppCompatActivity {

    Button btnOk;
    TextView textDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_alert_dialogue);

        textDialog = (TextView)findViewById(R.id.text_dialog) ;
        textDialog.setText("Hello, I'm the dialog text!");

        btnOk = (Button) findViewById(R.id.button_dialog);
        btnOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}

activity_alert_dialogue.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="300dp"
    android:layout_height="wrap_content"
    tools:context=".AlertDialogue">

    <TextView
        android:id="@+id/text_dialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="24dp"
        android:text="Hello, I'm the dialog text!"
        android:textColor="@android:color/darker_gray"
        android:textSize="16dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button_dialog"
        android:layout_width="wrap_content"
        android:layout_height="36dp"
        android:layout_margin="8dp"
        android:background="@android:color/transparent"
        android:text="Ok"
        android:textColor="@android:color/black"
        android:textSize="14dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/text_dialog" />


</android.support.constraint.ConstraintLayout>

Manifest:

<activity android:name=".AlertDialogue"
            android:theme="@style/AlertDialogNoTitle">
</activity>

Style:

<style name="AlertDialogNoTitle" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:windowNoTitle">true</item>
</style>

Solution 11 - Android

This worked for me.

Dailog dialog = new Dialog(MyActivity.this, R.style.dialogstyle);

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="dialogstyle" parent="android:style/Theme.Dialog">
        <item name="android:windowBackground">@null</item>
        <item name="android:windowNoTitle">false</item>
    </style>
</resources>

Solution 12 - Android

You can try this simple android dialog popup library. It is very simple to use on your activity.

When submit button is clicked try following code after including above lib in your code

Pop.on(this)
   .with()
   .title(R.string.title) //ignore if not needed
   .icon(R.drawable.icon) //ignore if not needed
   .cancelable(false) //ignore if not needed
   .layout(R.layout.custom_pop)
   .when(new Pop.Yah() {
       @Override
       public void clicked(DialogInterface dialog, View view) {
           Toast.makeText(getBaseContext(), "Yah button clicked", Toast.LENGTH_LONG).show();
       }
   }).show();

Add one line in your gradle and you good to go

dependencies {
    compile 'com.vistrav:pop:2.0'
}

Solution 13 - Android

**write this before adding view to dialog.**

dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJason RogersView Question on Stackoverflow
Solution 1 - AndroidsatView Answer on Stackoverflow
Solution 2 - AndroidPratik BhatView Answer on Stackoverflow
Solution 3 - AndroidRanjithkumarView Answer on Stackoverflow
Solution 4 - AndroidSagar VaghelaView Answer on Stackoverflow
Solution 5 - AndroidEvgeTymoView Answer on Stackoverflow
Solution 6 - AndroidMohit KanadaView Answer on Stackoverflow
Solution 7 - AndroidMehroz MunirView Answer on Stackoverflow
Solution 8 - AndroiddugguView Answer on Stackoverflow
Solution 9 - Androidmbm29414View Answer on Stackoverflow
Solution 10 - AndroidV.MarchView Answer on Stackoverflow
Solution 11 - AndroidJasmine JohnView Answer on Stackoverflow
Solution 12 - AndroidDharmesh GohilView Answer on Stackoverflow
Solution 13 - Androiddileep krishnanView Answer on Stackoverflow