今回は、Holo系のThemeを使いつつActivityの背景を透明する方法について調べてみました。
コード
いまどきのADTでAndroidプロジェクトを作成すると、以下のようなフォルダ構成で「3.x+ではHolo Themeを有効化、2.xでは従来のThemeを使用」となっているかと思います。そのため、それぞれのstyles.xmlに背景を透過にする設定を追加しています。
/res/values/styles.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<style name="AppTheme" parent="android:Theme.Light.NoTitleBar"> | |
<item name="android:windowIsTranslucent">true</item> | |
<item name="android:windowBackground">@android:color/transparent</item> | |
</style> | |
</resources> |
/res/values-v14/styles.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar"> | |
<item name="android:windowIsTranslucent">true</item> | |
<item name="android:windowBackground">@android:color/transparent</item> | |
</style> | |
</resources> |
まとめ
上記の方法を使うとDark系・Light系テーマの切り替えもできますし、Theme.Translucentを使うよりもレイアウトの自由度が増すと思います。
今回は、こちらのブログを参考にさせていただきました。
ReDo -Refrigerator Door- れいぞうこのドア
透過なActionBar
http://greety.sakura.ne.jp/redo/2011/08/actionbar.html
ActionBarを透過にして、ActionBar領域も含めて背景を描画する手法、どこかで使って見たいと思います。
この記事書かれたの1年以上も前なのですね。。
自分の周回遅れ感が...
0 件のコメント:
コメントを投稿