2014年1月8日 星期三

[Android] Android training速記-Adding the Action Bar

1. support library 下載
2. support library 設定
(1)先匯入library 專案 → import new Android project → 選擇Extra EX: v7-appcompat,
→ libs下的.jar按右鍵Add a Build Path (然後檔案會出現在reference library內) → 專案按右鍵Configure Build Path, 選擇EX: v7-appcompat和v4, 反選擇dependencies
之後此library會在eclipse以project的形式呈現, 不可刪除

(2)專案使用library
 專案按右鍵Properties → 選擇Android → 選擇Add, 路徑 EX: android-support-v7-appcompat

3.
  • android.support.v7.app.ActionBar when using the Support Library. 用此library可以定義public class MainActivity extends ActionBarActivity


  • android.app.ActionBar when developing only for API level 11 or higher. 用與不用的差異? 實驗結果都沒用到
4. Android 3.0後(SDK11以上), 使用 Theme.Holo類型的任一個Activity, 都包含Actionbar,(Theme.HolotargetSdkVersion 或minSdkVersion 設為11以上的default Theme)

5. Android 3.0~2.1,(SDK7~10), 要增加library:

ActionBarActivity,For example:
public class MainActivity extends ActionBarActivity { ... }

6. 修改onCreateOptionsMenu:
return super.onCreateOptionsMenu(menu);

7. manifest file, update either the <application> element or individual <activity> elements to use one of the Theme.AppCompat themes. For example: 是兩者擇一加入? →application下的activity
<activity android:theme="@style/Theme.AppCompat.Light" ... >
8. 目前不加<activity android:theme="@style/Theme.AppCompat.Light">跟 android.app.ActionBar 皆可執行? →前者要加

參考網誌:

沒有留言:

張貼留言