Android activity as dialog, but without a title bar

后端 未结 9 1794
暗喜
暗喜 2020-12-02 21:59

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

相关标签:
9条回答
  • 2020-12-02 22:17

    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>
    
    0 讨论(0)
  • 2020-12-02 22:21

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

    0 讨论(0)
  • 2020-12-02 22:25

    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>
    
    0 讨论(0)
  • 2020-12-02 22:32

    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.

    0 讨论(0)
  • 2020-12-02 22:34

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

    0 讨论(0)
  • 2020-12-02 22:36

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

    Try this

    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

    immediately before setContentView(R.layout.MyDialogActivity);

    0 讨论(0)
提交回复
热议问题