Android - FEATURE_NO_TITLE not working

放肆的年华 提交于 2019-12-20 03:18:00

问题


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);



来源:https://stackoverflow.com/questions/28080250/android-feature-no-title-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!