Android HelloWord编写方式介绍
创始人
2024-06-22 03:00:23
0

相信学过编程的人员都对各种语言的helloword程序的编写方式记忆犹新吧。在这里我们就为大家详细介绍一下有关Android HelloWord的编写方式,方便大家对这一操作系统编写方式的理解。#t#

先说说整个程序要做哪些内容吧,简单helloword 通过一个按钮点击在另一个acitvity出现文本Hello xiaoshengDAI

 

 

 

说下Android HelloWord做的步骤吧:

 

1.首先新建项目,我这边主要是测试Layout所以项目名就叫这个了。

2.我们要显示一个按钮,难后点击这个按钮就转到其他activity显示Hello xiaoshengDAI,新建类Layout主要来显示***个activity即button,

1).在main.xml文件中进行配置

Java代码

  1. < ?xml version="1.0" encoding="utf-8"?>   
  2. < LinearLayout xmlns:android=
    "http://schemas.android.com/apk/res/android"   
  3. android:orientation="vertical"   
  4. android:layout_width="fill_parent"   
  5. android:layout_height="fill_parent">   
  6. < Button android:id="@+id/button1"   
  7. android:layout_width="wrap_content"   
  8. android:layout_height="wrap_content"   
  9. android:text="来点我吧"/>   
  10. < /LinearLayout>   
  11. < ?xml version="1.0" encoding="utf-8"?> 
  12. < LinearLayout xmlns:android=
    "http://schemas.android.com/apk/res/android" 
  13. android:orientation="vertical" 
  14. android:layout_width="fill_parent" 
  15. android:layout_height="fill_parent">   
  16. < Button android:id="@+id/button1"   
  17. android:layout_width="wrap_content"   
  18. android:layout_height="wrap_content"   
  19. android:text="来点我吧"/>   
  20. < /LinearLayout>  

 

 

 

2).设置监听和跳转actiovity

 

 

Java代码

  1. package com.layout;   
  2. import android.app.Activity;   
  3. import android.content.Intent;   
  4. import android.os.Bundle;   
  5. import android.view.View;   
  6. import android.view.View.OnClickListener;   
  7. import android.widget.Button;   
  8. public class Layout extends Activity {   
  9. /** Called when the activity is first created. */   
  10. @Override   
  11. public void onCreate(Bundle savedInstanceState) {   
  12. OnClickListener listener1 = null;   
  13. Button botton1 = null;   
  14. listener1 = new OnClickListener(){   
  15. public void onClick(View v) {   
  16. Intent intent0 = new Intent(Layout.this,
    ActivityFrameLayout.class);   
  17. setTitle("FrameLayout");   
  18. startActivity(intent0);   
  19. }   
  20. };   
  21. super.onCreate(savedInstanceState);   
  22. setContentView(R.layout.main);   
  23. botton1 = (Button) findViewById(R.id.button1);   
  24. botton1.setOnClickListener(listener1);   
  25. }   
  26. }   
  27. package com.layout;  
  28. import android.app.Activity;  
  29. import android.content.Intent;  
  30. import android.os.Bundle;  
  31. import android.view.View;  
  32. import android.view.View.OnClickListener;  
  33. import android.widget.Button;  
  34. public class Layout extends Activity {  
  35. /** Called when the activity is first created. */  
  36. @Override  
  37. public void onCreate(Bundle savedInstanceState) {  
  38. OnClickListener listener1 = null;  
  39. Button botton1 = null;   
  40. listener1 = new OnClickListener(){  
  41. public void onClick(View v) {   
  42. Intent intent0 = new Intent(Layout.this,
    ActivityFrameLayout.class);   
  43. setTitle("FrameLayout");  
  44. startActivity(intent0);  
  45. }   
  46. };   
  47. super.onCreate(savedInstanceState);  
  48. setContentView(R.layout.main);  
  49. botton1 = (Button) findViewById(R.id.button1);  
  50. botton1.setOnClickListener(listener1);  
  51. }  

 

3.在Android HelloWord编写中,新建activityFrameLayout类和activityFrameLayout.xml文件

 

Java代码

  1. < ?xml version="1.0" encoding="utf-8"?>   
  2. < LinearLayout xmlns:android=
    "http://schemas.android.com/apk/res/android"   
  3. android:orientation="vertical"   
  4. android:layout_width="fill_parent"   
  5. android:layout_height="fill_parent"   
  6. >   
  7. < TextView   
  8. android:layout_width="fill_parent"   
  9. android:layout_height="wrap_content"   
  10. android:text="Hello xiaoshengDAI"   
  11. />   
  12. < /LinearLayout>   
  13. < ?xml version="1.0" encoding="utf-8"?> 
  14. < LinearLayout xmlns:android=
    "http://schemas.android.com/apk/res/android" 
  15. android:orientation="vertical" 
  16. android:layout_width="fill_parent" 
  17. android:layout_height="fill_parent" 
  18. < TextView   
  19. android:layout_width="fill_parent"   
  20. android:layout_height="wrap_content"   
  21. android:text="Hello xiaoshengDAI" 
  22. /> 
  23. < /LinearLayout>  

 

Java代码

  1. package com.layout;   
  2. import android.app.Activity;   
  3. import android.os.Bundle;   
  4. public class ActivityFrameLayout extends Activity {   
  5. @Override   
  6. protected void onCreate(Bundle savedInstanceState) {   
  7. super.onCreate(savedInstanceState);   
  8. setTitle("哈哈");   
  9. setContentView(R.layout.activityframelayout);   
  10. }   
  11. }   
  12. package com.layout;  
  13. import android.app.Activity;  
  14. import android.os.Bundle;  
  15. public class ActivityFrameLayout extends Activity {  
  16. @Override  
  17. protected void onCreate(Bundle savedInstanceState) {  
  18. super.onCreate(savedInstanceState);  
  19. setTitle("哈哈");  
  20. setContentView(R.layout.activityframelayout);  
  21. }  

4.对AndroidManifest.xml进行配置,将新建Activity配置文件加进来

 

Android HelloWord的Java代码

  1. < ?xml version="1.0" encoding="utf-8"?>   
  2. < manifest xmlns:android=
    "http://schemas.android.com/apk/res/android"   
  3. package="com.layout"   
  4. android:versionCode="1"   
  5. android:versionName="1.0">   
  6. < application android:icon="@drawable/icon" 
    android:label="@string/app_name">   
  7. < activity android:name=".Layout"   
  8. android:label="@string/app_name">   
  9. < intent-filter>   
  10. < action android:name="android.intent.action.MAIN" />   
  11. < category android:name=
    "android.intent.category.LAUNCHER" />   
  12. < /intent-filter>   
  13. < /activity>   
  14. < activity android:name=".ActivityFrameLayout" 
    android:label="activityFrameLayout">   
  15. < intent-filter>   
  16. < action android:name="android.intent.action.MAIN" />   
  17. < category android:name=
    "android.intent.category.LAUNCHER" />   
  18. < /intent-filter>   
  19. < /activity>   
  20. < /application>   
  21. < uses-sdk android:minSdkVersion="3" />   
  22. < /manifest>   
  23. < ?xml version="1.0" encoding="utf-8"?> 
  24. < manifest xmlns:android=
    "http://schemas.android.com/apk/res/android" 
  25. package="com.layout" 
  26. android:versionCode="1" 
  27. android:versionName="1.0"> 
  28. < application android:icon="@drawable/icon" 
    android:label="@string/app_name"> 
  29. < activity android:name=".Layout" 
  30. android:label="@string/app_name"> 
  31. < intent-filter> 
  32. < action android:name="android.intent.action.MAIN" /> 
  33. < category android:name=
    "android.intent.category.LAUNCHER" /> 
  34. < /intent-filter> 
  35. < /activity> 
  36. < activity android:name=".ActivityFrameLayout" 
    android:label="activityFrameLayout"> 
  37. < intent-filter> 
  38. < action android:name="android.intent.action.MAIN" /> 
  39. < category android:name=
    "android.intent.category.LAUNCHER" /> 
  40. < /intent-filter> 
  41. < /activity> 
  42. < /application> 
  43. < uses-sdk android:minSdkVersion="3" /> 
  44. < /manifest>  

5.Android HelloWord可以运行了,嘿嘿

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
Windows恶意软件20年“... 在Windows的早期年代,病毒游走于系统之间,偶尔删除文件(但被删除的文件几乎都是可恢复的),并弹...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
着眼MAC地址,解救无法享受D... 在安装了DHCP服务器的局域网环境中,每一台工作站在上网之前,都要先从DHCP服务器那里享受到地址动...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...