つ部 android 勉強会 2013年9月 発表資料
TRANSCRIPT
![Page 1: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/1.jpg)
AppCompat使ってみました
2013/9/14 つ部 Android 勉強会 2013年9月@nagakenjs
![Page 2: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/2.jpg)
自己紹介Twitter ID:@nagakenjs(ながけん)
お仕事:ソフト屋さんです。Java屋さんのはずですがCやC++もよく書きます。Androidの中の人になることが多いです。
たまに.NET Micro Frameworkで遊んでます。年末にかけて何かするかも。
![Page 3: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/3.jpg)
あなたのアプリにActionBarはありますか?
![Page 4: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/4.jpg)
ActionBar
こいつです
Honeycombより追加されたメニュー構造
アイコン、検索ボックス、ドロップダウンメニューなどを配置可能
![Page 5: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/5.jpg)
Andriodのシェア
http://developer.android.com/about/dashboards/index.html
2.2/2.3のシェアが3割まだまだサポート捨てられない
![Page 6: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/6.jpg)
ActionBar Sherlok
Andriod 2.xでActionBarが利用可能
サードパーティ製ライブラリ
http://actionbarsherlock.com/
![Page 7: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/7.jpg)
v7 appcompat libraryAndroid 2.1以降で使えるActionBarライブラリ
Android Support Library Rev.18で導入
Google謹製!
![Page 8: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/8.jpg)
導入方法(Eclipse)Action Bar用のサブプロジェクトを作成
<SDK>/extras/android/support/v7/appcompat をインポート
アプリからサブプロジェクトを参照
![Page 9: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/9.jpg)
導入方法 (Android Studio)
プロジェクトを作る時のウィザードで「Action Bar」にチェックを付ける(0.2.7から)
またはbuild.gradleに以下を設定
dependencies { compile 'com.android.support:appcompat-v7:18.0.0' compile 'com.android.support:support-v4:18.0.0'}
![Page 10: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/10.jpg)
どうやって使うの?
![Page 11: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/11.jpg)
利用方法(その1)Activity を ActionBarActivityに置き換える
テーマをAndroidManifest.xmlに設定する
Theme.AppCompatTheme.AppCompat.LightTheme.AppCompat.Light.DarkActionBar
public class MainActivity extends ActionBarActivity
![Page 12: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/12.jpg)
利用方法(その2)メニューは標準APIが使用可能
ActionBarで拡張された部分はMenuItemCompatを使用
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem item = menu.add(0, MENU_ID, Menu.NONE, "menu"); MenuItemCompat.setShowAsAction( item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); super.onCreateOptionsMenu(menu, inflater);}
![Page 13: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/13.jpg)
利用方法(その3)XMLファイルでメニューを扱う場合
ActionBar拡張部分は別途名前空間を定義する
<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:yourapp="http://schemas.android.com/apk/res-auto" > <item android:id="@+id/menu_settings" android:icon="@drawable/ic_menu_preferences" android:title="@string/menu_settings" yourapp:showAsAction="ifRoom" /></menu>
![Page 14: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/14.jpg)
利用方法(その4)android.support.v7.app.ActionBar
appcompatで追加
android.app.ActionBarとAPIの互換性あり
// ActionBarActivityのメソッド内ActionBar actionBar = getSupportActionBar();
![Page 15: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/15.jpg)
つまずく点ListActivityの代替クラスがない
ListFragmentを使うべき?
Andriod Studioでテーマが使えない
0.2.7にバージョンアップする
![Page 16: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/16.jpg)
ActionBar Sherlockとの違いは?
![Page 17: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/17.jpg)
ActionBarSherlockとの違い
各ライブラリのクラス数・リソース数
クラス数リソース数(png + xml)
AppCompat
ActionBar Sherlock
56ファイル 291ファイル
87ファイル 341ファイル
![Page 18: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/18.jpg)
ActionBarSherlockとの違い
AppCompat ActionBarSherlock
• ActionBar基本機能
•タブバー•ポップアップメニュー•検索ビュー•共有
• ActionBar基本機能
•各種Activityの拡張
•各種Fragmentの拡張
•タブバー•メニューの拡張•ポップアップメニュー•検索ビュー•共有
![Page 19: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/19.jpg)
ActionBarSherlockとの違い
apkのサイズ
• Android StudioでHello Worldプロジェクトを作成
• build.gradleにDebug版とRelease版のapkを作るよう設定
Debug Release
AppCompat
ActionBar Sherlock
651,819 byte 635,201 byte
731,848 byte 708,439 byte
![Page 20: つ部 Android 勉強会 2013年9月 発表資料](https://reader034.vdocuments.pub/reader034/viewer/2022052311/55a272c31a28ab086c8b45ec/html5/thumbnails/20.jpg)
まとめAndroid 2.1からActionBarが利用可能
Activityやテーマを置き換えて使う
ActionBar Sherlockと比べるとコンパクト
標準提供されているので導入が容易