Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

android - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...