Android (3.0) Action Bar dont want to Go

2020-02-09 04:42发布

I am working with XOOM and trying to hide action bar. So i follow the instruction did the following in manifest file:

uses-sdk android:minSdkVersion="11" android:targetSdkVersion="11"

also set activity theme.

android:theme="@android:style/Theme.Holo.NoActionBar"

unfortunately i can still see the action bar. so i remove the holo action part from my manifest and added following code

ActionBar actionBar = getActionBar(); actionBar.hide();

getting null pointer exception from hide() method. so i understand getActionBar() is returning null. Now i am curious what i am missing?

5条回答
淡お忘
2楼-- · 2020-02-09 05:19

I came to exactly the same conclusion. If you can't make the ActionBar show on the screen it is most likely either :

  • window has no title; ActionBar is essentially a glorified title bar, thus no title= no ActionBar, although this is nowhere mentioned in the docs

  • you tried to call the getActionBar() method prior setting the content view in the activity. In this case, this method returns null. Again, nowhere mentioned in the docs, and if you try to construct/modify the ActionBar as a part of the custom view constructor, you are out of luck.

More about my explorations of ActionBar in Honeycomb can be found on my blog here

查看更多
一夜七次
3楼-- · 2020-02-09 05:25

The action bar in Honeycomb cannot be hidden because there are no physical buttons to back out of the app, so you could trap users in the app if the action bar is hidden. The best you can do is put the bar in "lights out" mode, where you get the small dots in place of the normal icons in the bar.

See this link: Is there a way to hide the system bar in Android 3.0? It's an internal device and I'm managing navigation

查看更多
欢心
4楼-- · 2020-02-09 05:29

you can hide the action bar (which will display in the top of the screen). If your activity is tab activity then use the following line after the setcontentview line

getParent().getActionBar().hide(); 

If it is a normal activity then use

getActionBar().hide(); 

And setting on manifest is also working for me, but only to the particular activity you can set like this not to application.

android:theme="@android:style/Theme.Holo.NoActionBar"
查看更多
Summer. ? 凉城
5楼-- · 2020-02-09 05:35

this helped me.. edited values/styles.xml like this

<resources>

<style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar" />

</resources>
查看更多
孤傲高冷的网名
6楼-- · 2020-02-09 05:38

Theme.Holo.NoActionBar isn't public in the framework- Instead, you can declare your own style like this:

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
</style>
查看更多
登录 后发表回答