77

I have an activity that has the following set as theme:

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

However, there is a title bar in the activity-dialog that appears, that uses up the little available space that I have. How can I remove it?

Shade
  • 9,936
  • 5
  • 60
  • 85

9 Answers9

146

Try doing requestWindowFeature(Window.FEATURE_NO_TITLE); in onCreate. It'll need to be done immediately after calling super.onCreate and just before setContentView.

Siddharth
  • 9,349
  • 16
  • 86
  • 148
Femi
  • 64,273
  • 8
  • 118
  • 148
  • 1
    Have you tried this with 2.2? I am getting a `Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features` Exception, but maybe I am doing something else wrong. – Eleni Jun 03 '12 at 10:55
  • You're probably using another window title feature in code, or using a theme that does other things to the title. – Femi Jun 07 '12 at 01:52
  • 16
    this wll not work in `AppCompactActivity`. You sholud add the @zackygaurav answer so that the user who are using the `AppCompatActivity` will get the proper information. – Moinkhan Jul 16 '16 at 11:42
  • @Moinkhan so how would it work for 'AppCompactActivity'? – Yousuf Sohail Feb 04 '19 at 10:00
145

For those who are using AppCompatActivity, above answers may not work.

Try this

supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

immediately before setContentView(R.layout.MyDialogActivity);

zackygaurav
  • 4,369
  • 5
  • 26
  • 40
  • 10
    Or add `true` to your style i.e. without the **android** prefix – Rehan Sep 29 '16 at 12:12
  • 1
    Just one more thing: Do not use `ConstraintLayout` at the root of your layout or your activity will not appear on screen. – Van Aug 07 '18 at 17:53
114

You can define your own theme:

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

(Tip of the hat to @Rehan) If you're using the compatibility library, you should pick an AppCompat parent theme and leave off the android: prefix. For example:

<style name="NoTitleDialog" parent="@style/Theme.AppCompat.Dialog">
    <item name="windowNoTitle">true</item>
</style>
Hein
  • 2,675
  • 22
  • 32
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • 4
    Thanks for this. It's probably a better approach, but I ended up using requestWindowFeature. Thanks anyway :) – Shade Jun 12 '11 at 22:22
  • 7
    Just adding: Use it without **android** prefix for `AppCompatActivity` i.e. add `true` to your style. – Rehan Sep 29 '16 at 12:10
  • I've found good concept on many sources but none of them talking about AppCompat and none-Appcompat, thanks – Somwang Souksavatd Mar 18 '19 at 05:36
30

If you are using AppCompatActivity in which you are forced to use Theme.AppCompat.xxx for everything, you can remove the dialog title or actionbar in styles.xml using this:

<style name="Theme.MyDialog" parent="Theme.AppCompat.Light.Dialog">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

Notice the use of name="windowActionBar", instead of name="android:windowActionBar".

Neoh
  • 15,906
  • 14
  • 66
  • 78
  • I was trying helplessly using AppCompat AND using android namespace in the windowNoTitle declaration. THANKS! – romulof Feb 03 '16 at 19:48
6

This one worked for me.

I was able to disable the title

style.xml

<style name="AppDialogScreenTheme" parent="Base.Theme.MaterialComponents.Light.Dialog">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

AndroidManifest.xml

  <activity
        android:name=".MyActivity"
        android:theme="@style/AppDialogScreenTheme">

  </activity>
Javid Sattar
  • 749
  • 8
  • 14
5

This one worked for me for appcompat.

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
Ajji
  • 3,068
  • 2
  • 30
  • 31
5

If you are using AppCompatActivity requestWindowFeature(Window.FEATURE_NO_TITLE) is not working.

for this you can create custom theme in values/style.xml as below:

   <style name="NoTitleDialog" parent="Theme.AppCompat.Dialog.Alert">
        <item name="windowNoTitle">true</item>
    </style>

please note that item name:"windowNoTitle" not item name:"android:windowNoTitle"

In menifest.xml apply this custom theme as

<activity android:name=".activity.YourActivity"
            android:theme="@style/NoTitleDialog"/>

or you can use getSupportActionBar().hide() to programmatically hide action bar.

Sangram Haladkar
  • 707
  • 9
  • 22
0

This works for me, may it helps someone too :

style.xml

<style name="NoTitleActivityDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="windowNoTitle">true</item>
</style>

AndroidManifest.xml

   <activity
        android:name=".DialogActivity"
        android:theme="@style/NoTitleActivityDialog"/>
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
0

I try requestWindowFeature(Window.FEATURE_NO_TITLE); but not working for me, if you are like me so do this : first Add the following code in your res/values/styles.xml:

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

Pass the theme to your dialog:

Dialog dialog = new Dialog(this, R.style.NoTitleDialog);

that's it very simple

jenos kon
  • 504
  • 4
  • 7