Activity with action bar but without title?

丶灬走出姿态 提交于 2019-12-21 02:56:09

问题


How to achieve this? It seems very simple, but actually it's not easy to do it in acceptable way. I tried this:

1) in AndroidManifest I set activity theme to Theme.NoTitleBar. However, in my Activity then getActionBar() method returns null => UNUSABLE

2) I hide title programatically in my activity by calling:

actionbar.setDisplayShowTitleEnabled(false);
actionbar.setDisplayShowHomeEnabled(false);

and it helped, but there's a little delay, so I can see title bar maybe quarter of second after activity launch, then it disappears. It looks really lame.

Are there other options?


回答1:


Apply a custom theme to your Activity, something like:

<style name="TestTheme" parent="android:Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/TestActionBar</item>
</style>

<style name="TestActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@drawable/actionbar_background</item>
    <item name="android:displayOptions"></item>
</style>

This will show the action bar with the logo, but no title.




回答2:


Have u try bellow code :-

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.ur activityxml);

or also try below one

    requestWindowFeature(Window.FEATURE_NO_TITLE);  

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
            WindowManager.LayoutParams.FLAG_FULLSCREEN);  

    setContentView(R.layout.activityxml);


来源:https://stackoverflow.com/questions/14854309/activity-with-action-bar-but-without-title

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