Android activity as dialog, but without a title ba

2019-01-11 05:51发布

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?

8条回答
乱世女痞
2楼-- · 2019-01-11 05:51

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

查看更多
Melony?
3楼-- · 2019-01-11 05:53

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

查看更多
家丑人穷心不美
4楼-- · 2019-01-11 05:58

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>
查看更多
闹够了就滚
5楼-- · 2019-01-11 05:58

for dialogs, you can do it like:

Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
查看更多
Ridiculous、
6楼-- · 2019-01-11 06:04

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"/>
查看更多
对你真心纯属浪费
7楼-- · 2019-01-11 06:05

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.

查看更多
登录 后发表回答