`

Android入门 HelloWord

阅读更多

 

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

 

具体包结构如下图

 

 

 

说下做的步骤吧:

 

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.       
  7.     <Button android:id="@+id/button1"          
  8.             android:layout_width="wrap_content"   
  9.             android:layout_height="wrap_content"   
  10.             android:text="来点我吧"/>         
  11.               
  12. </LinearLayout>  

 

 

 

   2).设置监听和跳转actiovity

 

 

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

 

3.新建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>  

 

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

 

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

 

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>   

 5.可以运行了,嘿嘿

 

分享到:
评论
2 楼 勇气魄力 2013-05-12  
好好,学习了
1 楼 jsj_064 2010-08-02  
我刚学android,谢谢你这篇文章。

相关推荐

Global site tag (gtag.js) - Google Analytics