Uploaded on

Android App Dev lesson serial - Activity

Android App Dev lesson serial - Activity

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
181
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
8
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Activity Michael Pan
  • 2. The project
  • 3. Blank Activity
  • 4. Layout - activity_record.xml
  • 5. Project View
  • 6. AndroidManifest.xml DailyRecord > app > src > main > AndroidManifest.xml
  • 7. Application attributes <?xml version="1.0" encoding="utf-8"?>! <manifest xmlns:android="http://schemas.android.com/apk/res/android"! package="com.zencher.dailyrecord.app" >! ! <application! android:allowBackup="true" ! android:icon="@drawable/ic_launcher"! android:label="@string/app_name"! android:theme="@style/AppTheme" >! <activity! android:name="com.zencher.dailyrecord.app.RecordActivity"! android:label="@string/app_name" >! <intent-filter>! <action android:name="android.intent.action.MAIN" />! ! <category android:name="android.intent.category.LAUNCHER" />! </intent-filter>! </activity>! </application>! ! </manifest> http://bit.ly/1msJ804 Backup App image
  • 8. Change icon @drawable/ic_launcher app > src > main > res > drawable-xxxx
  • 9. Run - Change Icon
  • 10. Application attributes - android:label <?xml version="1.0" encoding="utf-8"?>! <manifest xmlns:android="http://schemas.android.com/apk/res/android"! package="com.zencher.dailyrecord.app" >! ! <application! android:allowBackup="true" ! android:icon="@drawable/ic_launcher"! android:label="@string/app_name"! android:theme="@style/AppTheme" >! <activity! android:name="com.zencher.dailyrecord.app.RecordActivity"! android:label="@string/app_name" >! <intent-filter>! <action android:name="android.intent.action.MAIN" />! ! <category android:name="android.intent.category.LAUNCHER" />! </intent-filter>! </activity>! </application>! ! </manifest>
  • 11. Another resource @string/app_name app > src > main > res > values > strings.xml
  • 12. Tag - activity <?xml version="1.0" encoding="utf-8"?>! <manifest xmlns:android="http://schemas.android.com/apk/res/android"! package="com.zencher.dailyrecord.app" >! ! <application! android:allowBackup="true" ! android:icon="@drawable/ic_launcher"! android:label="@string/app_name"! android:theme="@style/AppTheme" >! <activity! android:name="com.zencher.dailyrecord.app.RecordActivity"! android:label="@string/app_name" >! <intent-filter>! <action android:name="android.intent.action.MAIN" />! ! <category android:name="android.intent.category.LAUNCHER" />! </intent-filter>! </activity>! </application>! ! </manifest> Class name
  • 13. activity - android:label <?xml version="1.0" encoding="utf-8"?>! <manifest xmlns:android="http://schemas.android.com/apk/res/android"! package="com.zencher.dailyrecord.app" >! ! <application! android:allowBackup="true" ! android:icon="@drawable/ic_launcher"! android:label="@string/app_name"! android:theme="@style/AppTheme" >! <activity! android:name="com.zencher.dailyrecord.app.RecordActivity"! android:label="@string/app_name" >! <intent-filter>! <action android:name="android.intent.action.MAIN" />! ! <category android:name="android.intent.category.LAUNCHER" />! </intent-filter>! </activity>! </application>! ! </manifest>
  • 14. Create a new string tag
  • 15. Run @string/main_activity_label
  • 16. intent-filter <?xml version="1.0" encoding="utf-8"?>! <manifest xmlns:android="http://schemas.android.com/apk/res/android"! package="com.zencher.dailyrecord.app" >! ! <application! android:allowBackup="true" ! android:icon="@drawable/ic_launcher"! android:label="@string/app_name"! android:theme="@style/AppTheme" >! <activity! android:name="com.zencher.dailyrecord.app.RecordActivity"! android:label="@string/app_name" >! <intent-filter>! <action android:name="android.intent.action.MAIN" />! ! <category android:name="android.intent.category.LAUNCHER" />! </intent-filter>! </activity>! </application>! ! </manifest>
  • 17. intent Message among activities intent-filter filter intent event must have a action android.intent.action.MAIN - the initial activity category android.intent.category.LAUNCHER - Should be displayed in the top-level launcher
  • 18. Add some Control EditText Button
  • 19. activity_record.xml in layout app > src > main > res > layout > activity_record.xml <RelativeLayout >! ! <TextView />! ! <EditText />! ! <Button />! ! </RelativeLayout>
  • 20. Design & Text - layout xml Design Text
  • 21. RecordActivity.java app > src > main > java > (domain) > RecordActivity.java public class RecordActivity extends Activity {! ! @Override! protected void onCreate(Bundle savedInstanceState) {! super.onCreate(savedInstanceState);! setContentView(R.layout.activity_record);! } ! ! ! // ignored… ! }
  • 22. R Auto generated Class files in res/ will be the field in R app > build > source > r > debug > (domain) > R
  • 23. layout xml in R
  • 24. Compiling process res/ AndroidManifest.xml R.java Asset Packaging Tool (aapt) src/ RecordActivity.java Compile Java Java bytecode .classCross Compile to Dalvik Dalvik bytecode .dex Compiled Resource Build & Sign apk Android Package .apk Install & Run
  • 25. setContentView(R.layout.activity_record); <RelativeLayout >! ! <TextView />! ! <EditText />! ! <Button />! ! </RelativeLayout> ClassLoader.loadClass(“RelativeLayout”) RelativeLayout ClassLoader.loadClass(“TextView”) TextView EditText Button ClassLoader.loadClass(“EditText”) ClassLoader.loadClass(“Button”)
  • 26. Run
  • 27. Get instance into variable
  • 28. import class option + Enter
  • 29. EditText & Button
  • 30. Get instance in Activity findViewById() protected void onCreate(Bundle savedInstanceState) {! super.onCreate(savedInstanceState);! setContentView(R.layout.activity_record);! mTopTextView = (TextView) findViewById(R.id.textView);! } activity_record.xml
  • 31. Apply into three variables
  • 32. OnClickListener
  • 33. View.OnClickListener new View.OnClickListener() {! ! @Override! ! public void onClick(View v) {! ! ! mTopTextView.setText(mInputView.getText());! ! }! }
  • 34. Question