Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppCompatActivity as a dialog without title

I have an Activity inherited from AppCompactActivity. in manifest for activity set theme:

<style name="Theme.custom" parent="Theme.AppCompat.Light.Dialog">     <item name="android:windowNoTitle">true</item>     <item name="colorPrimary">@color/primary</item>     <item name="colorPrimaryDark">@color/primary_dark</item>     <item name="colorAccent">@color/accent</item>     <item name="colorButtonNormal">@color/accent</item>     <item name="android:buttonStyle">@style/ButtonStyle</item> </style> 

When I run activity, it shows as a dialog, but title is shown! i try supportRequestWindowFeature(Window.FEATURE_NO_TITLE) and RequestWindowFeature(Window.FEATURE_NO_TITLE) but title still displayed. Please let me know, What is wrong?


Edit

I solve it, only change android:windowNoTitle to windowNoTitle! because i am use AppCompactActvity!

like image 759
h.kelidari Avatar asked May 12 '15 07:05

h.kelidari


2 Answers

If you are having AppCompatActivity then the following won't work

requestWindowFeature(Window.FEATURE_NO_TITLE);

The simple way is to set it in the style.xml file.

<style name="mytheme" parent="Theme.AppCompat.Light.Dialog">     <item name="windowNoTitle">true</item> </style> 

It is name="windowNoTitle", not name="android:windowNoTitle"

If you want to remove it programmatically then add the following in onCreate()

getSupportActionBar().hide(); 
like image 190
gprathour Avatar answered Sep 21 '22 04:09

gprathour


AppCompatActivity is different than Activity and has its own features. For the same purpose, you can simply use -

supportRequestWindowFeature(Window.FEATURE_NO_TITLE); 

You can look up the documentation here

Note: Add this before setContentView() to avoid crash.

like image 43
Al Amin Avatar answered Sep 20 '22 04:09

Al Amin