Learning Android4.0 's Actionbar, a particularly disgusting problem, must be written down.
I started the new 2.2 project, later wanted to test Actionbar, see the document said 11 later to use, I directly changed the project into a min:14,target:17. This is also the beginning of the hidden danger.
Call the following sentence in the program to get Actionbar, but the return is always null, do not know why? It's been an afternoon of testing.
ActionBar Mactionbar = Getactionbar ();
I created a new project and created the project for SDK 14 directly, so I could not return null. I am particularly puzzled, compared for a long time, still did not find out where the problem. In fact, the clever programmer should have thought, certainly is the theme question, I did not think at that time.
Evening supper, come back to ask colleagues only know, originally is my theme set of troops, because I Project is 2.2 before, theme set is:
<style name= "Appbasetheme" parent= "Android:Theme.Light" >
The problem is here.
Then why do I have to build a new project? I overlooked one point: my new project has 3 theme:
1) Values--styles.xml
<!--
Base application theme, dependent on API level. This theme is replaced
By Appbasetheme from Res/values-vxx/styles.xml on newer devices.
-
<style name= "Appbasetheme" parent= "Android:Theme.Light" >
<!--
Theme customizations available in newer API levels can go
Res/values-vxx/styles.xml, while customizations related to
Backward-compatibility can go here.
-
</style>
2) values-v11-Styles.xml
<!--
Base application theme for API 11+. This theme completely replaces
Appbasetheme from Res/values/styles.xml on API 11+ devices.
-
<style name= "Appbasetheme" parent= "Android:Theme.Holo.Light" >
<!--API Theme customizations can go to here. -
</style>
3) Values-v14-Styles.xml
<!--
Base application theme for API 14+. This theme completely replaces
Appbasetheme from BOTH Res/values/styles.xml and
Res/values-v11/styles.xml on API 14+ devices.
-
<style name= "Appbasetheme" parent= "Android:Theme.Holo.Light.DarkActionBar" >
<!--API Theme customizations can go. -
</style>
Read it. This means: On the SDK 11 device, the second place will be used, and SDK 14 will use the third place, so it is normal. And my original project was changed from 2.2, and there is no values-v11 values-v14 these 2 files, so no.
Baidu a bit, look online also have the same friend met the same problem, I guess all and my problem is the same. Another friend said it was a bug, but it was not, and it didn't find the most fundamental reason. The following friend at least wrote his own Test experience, but also to me a little help to put.
Http://www.cnblogs.com/shortboy/archive/2013/04/18/3029029.html
The friend mentioned the addition of the following can be out, but the background is black, I tried, indeed as he said.
GetWindow (). Requestfeature (Window.feature_action_bar);
This article is from "Little book" blog, please make sure to keep this source http://8988940.blog.51cto.com/8978940/1584086
Android actionbar return NULL problem