2014年1月7日 星期二

[Android] Android training速記-Building Your First App

1. android:layout_weight="1"     android:layout_width="0dp" 並用的相互關係?

→ android:layout_width設為0增進了 layout performance, 因為設定"wrap_content"系統還要去計算剩餘空間, 沒有效益

2. android:hint="@string/edit_message" →未輸入字串時顯示的文字

3. command line位置?
  • Or from a command line, change directories to the root of your Android project and execute:
    ant debug
    adb install bin/MyFirstApp-debug.apk
4. target version需與執行環境相同才可執行
5. layout預設19版, 按鈕超出layout, 18版卻正常顯示?
6. android:onClick="sendMessage" 按鈕按下去時呼叫的方法
 MainActivity 對應方法程式碼
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
    // Do something in response to button
}  
該方法一定要:
  • Be public
  • Have a void return value
  • Have a View as the only parameter (this will be the View that was clicked)
7.  Ctrl + Shift + O 匯入類別庫

8. intent.putExtra(EXTRA_MESSAGE, message);

An Intent can carry a collection of various data types as key-value pairs called extras. The putExtra()method takes the key name in the first parameter and the value in the second parameter.

9. Intent可建立一Activity, 也可將a Bundle of data傳到Activity

10. public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE"利用套件名稱, 為 intent's extra定義key

11.  getActionBar() 要API 11以上, 
用 @SuppressLint("NewApi") tag 在 onCreate() 方法來避免  lint 錯誤
.Lint是一个静态检查器,它围绕Android项目的正确性、安全性、性能、可用性以及可访问性进行分析。它检查的对象包括XML资源、位图、ProGuard配置文件、源文件甚至编译后的字节码。
这一版本的Lint包含了API版本检查、性能检查以及其他诸多特性。其中还有一个重要的改动是Lint可以使用@SuppressLint标注忽略指定的警告。
http://blog.csdn.net/cxb5241/article/details/8540187

12. Android 4.1以後, 以android:parentActivityName 決定預設的導航行為, 像是Up navigation, 較舊的版本可以using the Support Library and adding the <meta-data> element
13. 除錯
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);

EXTRA_MESSAGE位置為String name, 所以不可加引號, 它是public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE"; 這裡取名作為intent動作傳遞的封包名字, 以防止不正確的Activity接收到 , message則為String Value

沒有留言:

張貼留言