Android activity as dialog, but without a title bar
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?
Try doing requestWindowFeature(Window.FEATURE_NO_TITLE);
in onCreate
. It'll need to be done immediately after calling super.onCreate
and just before setContentView
.
For those who are using AppCompatActivity
, above answers may not work.
Try this
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
immediately before setContentView(R.layout.MyDialogActivity);
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>
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"
.