[android] Android Dialog: Removing title bar

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

    <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>/>

This question is related to android layout dialog

The answer is


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:-

    <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>


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>

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();

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);


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();

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);

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'
}

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>

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.


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.


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>

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

dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to layout

This view is not constrained What's the difference between align-content and align-items? CSS Flex Box Layout: full-width row and columns Fill remaining vertical space with CSS using display:flex What is setContentView(R.layout.main)? How to change line color in EditText Scrolling a flexbox with overflowing content UICollectionView - Horizontal scroll, horizontal layout? How to style a div to be a responsive square? 100% width Twitter Bootstrap 3 template

Examples related to dialog

Disable click outside of angular material dialog area to close the dialog (With Angular Version 4.0+) How to change DatePicker dialog color for Android 5.0 Android simple alert dialog Swift alert view with OK and Cancel: which button tapped? How to make a edittext box in a dialog How to check if activity is in foreground or in visible background? jquery ui Dialog: cannot call methods on dialog prior to initialization JavaScript: Create and save file Prevent Android activity dialog from closing on outside touch How to use OpenFileDialog to select a folder?