原本新建好的Android背景是黑的,
但新近建的Android程式,背景是白的;
查了一下,
原本是在 AndroidManifest.xml中多了android:theme="@style/AppTheme"
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
反正是程式自行建立的,所以應該不是壞事,
結果問題來了,在Activity中的onCreateOptionsMenu竟然跑不進去,
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Log.d(TAG, "onCreateOptionsMenu");
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
在Log裡面居然看不到它印出onCreateOptionsMenu的Log,
趕緊上網路查查去;
原來要修改style.xml(這也是程式自己產生的)
<resources>
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 in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
原本的Theme使用是android:Theme.Light是不會產生Menu bar(Action bar)的,
要用android:Theme.Holo.Light來取代,修改如下:
<resources>
<!--
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.Holo.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
這樣程式就會正常了。