ActionBarは、Android 3系から登場したUIで、太いタイトルバーにメニューやボタンなどを付けて、アプリのさまざまな操作ができるようにしたUI・・・。
ActionBar | Android Developers
基本的には標準で搭載されているが、これまでのactivity_main.xmlなどのlayoutにはActionBarが定義されていない・・・。
ActionBarはどこから来たのだろう・・・。
ActionBarが使えるかどうかは、Activity.getActionBarでActionBarオブジェクトが取得できるかで知ることができる・・・。
そこで、
getActionBarがnullなら、"actionBar is null!"とトースト表示・・・。
取得出来たら、actionBar.setTitleで"Exist actionBar!!"をタイトルにセットする・・・。
ちなみにこのプロジェクトは、
相変わらず、"None"で作っている・・・。
しかし、実行すると、
"Exist actionBar!!"、つまりアクションバーは付いている・・・。
実は、さっきのTheme選択は、実際には関係ないようだ・・・。(少なくともEmpty Activityにおいては・・・。)
どういうことだろう・・・。
styles.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>
Android 4.0からのActionBar再入門 スマートフォン向けのアクションバーの使い方 | TechBooster
ここによると、Theme.Blackはアクションバーなしらしい・・・。
Theme.Lightもアクションバーがなかった・・・。(確認済み)
しかし、現実にはアクションバーが付いている・・・。
Themeをちょっと変えてみる・・・。
Theme.Holo.NoActionBarにして、確実にアクションバーがなくなるように・・・。
変わらない・・・。
どうも、ここは関係ない模様・・・。
実は、
values/styles.xmlではなくて、
values-v14/styles.xmlが本命だった・・・。
(Android 4 == API v14~だから当然なのだが・・・。)
Theme.Holo.Light.DarkActionBar・・・。
そりゃ、アクションバーが付くわけである・・・。
元々この状態なのだが、
<resources> <!-- 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"> --> <style name="AppBaseTheme" parent="android:Theme.Holo.NoActionBar"> <!-- API 14 theme customizations can go here. --> </style> </resources>
Theme.Holo.NoActionBarにして、確実にアクションバーが消えるようにする・・・。
アクションバーが消えた・・・。getActionBarがnullの模様・・・。
元に戻せば、
また、アクションバーが付く・・・。
というわけで、Android 4系の場合、アクションバーはvalues-v14/styles.xmlのThemeによって付くかどうかが決まるようだ・・・。
Sample/android/ActionBar/ActionBar/src/ActionBar/ActionBar_ at master · bg1bgst333/Sample · GitHub