Android - FEATURE_NO_TITLE not working

2019-02-27 11:31发布

问题:

I am trying to display my about us page via layout, so I don't need any title bar. I tried:

Dialog d = new Dialog(this);
d.setContentView(R.layout.about_us);
d.setCanceledOnTouchOutside(true);
d.requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
d.show();

but when I click on the menu item, it force closes. when I comment the third line of the code above, it shows my layout with title bar, which I don't need. P.S.: my activity extends ActionBarActivity, is this the reason? If yes then I need an alternative.

回答1:

Pass a theme to your dialog can remove the title bar for you.

  1. Add the following code in your res/values/styles.xml:
<style name="NoTitleDialog" parent="@android:Theme.Dialog">
    <item name="android:windowNoTitle">true</item>
</style>
  1. Pass the theme to your dialog:

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