温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android HelloWord编写方式是什么

发布时间:2021-11-11 15:54:26 阅读:160 作者:柒染 栏目:移动开发
Android开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

Android HelloWord编写方式是什么,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

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

  • Android多媒体播放功能的代码解析

  • Android选项卡具体代码编写方式介绍

  • Android常用技巧编写方式总结

  • Android特点总结介绍

  • Android内核相关内容总结

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

说下Android HelloWord做的步骤吧:

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

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

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

Java代码

< ?xml version="1.0" encoding="utf-8"?>   < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent">   < Button android:id="@+id/button1"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:text="来点我吧"/>   < /LinearLayout>   < ?xml version="1.0" encoding="utf-8"?> < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">   < Button android:id="@+id/button1"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:text="来点我吧"/>   < /LinearLayout>  

2).设置监听和跳转actiovity

Java代码

package com.layout;   import android.app.Activity;   import android.content.Intent;   import android.os.Bundle;   import android.view.View;   import android.view.View.OnClickListener;   import android.widget.Button;   public class Layout extends Activity {   /** Called when the activity is first created. */   @Override   public void onCreate(Bundle savedInstanceState) {   OnClickListener listener1 = null;   Button botton1 = null;   listener1 = new OnClickListener(){   public void onClick(View v) {   Intent intent0 = new Intent(Layout.this,ActivityFrameLayout.class);   setTitle("FrameLayout");   startActivity(intent0);   }   };   super.onCreate(savedInstanceState);   setContentView(R.layout.main);   botton1 = (Button) findViewById(R.id.button1);   botton1.setOnClickListener(listener1);   }   }   package com.layout;  import android.app.Activity;  import android.content.Intent;  import android.os.Bundle;  import android.view.View;  import android.view.View.OnClickListener;  import android.widget.Button;  public class Layout extends Activity {  /** Called when the activity is first created. */  @Override  public void onCreate(Bundle savedInstanceState) {  OnClickListener listener1 = null;  Button botton1 = null;   listener1 = new OnClickListener(){  public void onClick(View v) {   Intent intent0 = new Intent(Layout.this,ActivityFrameLayout.class);   setTitle("FrameLayout");  startActivity(intent0);  }   };   super.onCreate(savedInstanceState);  setContentView(R.layout.main);  botton1 = (Button) findViewById(R.id.button1);  botton1.setOnClickListener(listener1);  }  } 

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

Java代码

< ?xml version="1.0" encoding="utf-8"?>   < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   >   < TextView   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="Hello xiaoshengDAI"   />   < /LinearLayout>   < ?xml version="1.0" encoding="utf-8"?> < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > < TextView   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="Hello xiaoshengDAI" /> < /LinearLayout>  

Java代码

package com.layout;   import android.app.Activity;   import android.os.Bundle;   public class ActivityFrameLayout extends Activity {   @Override   protected void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   setTitle("哈哈");   setContentView(R.layout.activityframelayout);   }   }   package com.layout;  import android.app.Activity;  import android.os.Bundle;  public class ActivityFrameLayout extends Activity {  @Override  protected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setTitle("哈哈");  setContentView(R.layout.activityframelayout);  }  }

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

Android HelloWord的Java代码

< ?xml version="1.0" encoding="utf-8"?>   < manifest xmlns:android="http://schemas.android.com/apk/res/android"   package="com.layout"   android:versionCode="1"   android:versionName="1.0">   < application android:icon="@drawable/icon" android:label="@string/app_name">   < activity android:name=".Layout"   android:label="@string/app_name">   < intent-filter>   < action android:name="android.intent.action.MAIN" />   < category android:name="android.intent.category.LAUNCHER" />   < /intent-filter>   < /activity>   < activity android:name=".ActivityFrameLayout" android:label="activityFrameLayout">   < intent-filter>   < action android:name="android.intent.action.MAIN" />   < category android:name="android.intent.category.LAUNCHER" />   < /intent-filter>   < /activity>   < /application>   < uses-sdk android:minSdkVersion="3" />   < /manifest>   < ?xml version="1.0" encoding="utf-8"?> < manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.layout" android:versionCode="1" android:versionName="1.0"> < application android:icon="@drawable/icon" android:label="@string/app_name"> < activity android:name=".Layout" android:label="@string/app_name"> < intent-filter> < action android:name="android.intent.action.MAIN" /> < category android:name="android.intent.category.LAUNCHER" /> < /intent-filter> < /activity> < activity android:name=".ActivityFrameLayout" android:label="activityFrameLayout"> < intent-filter> < action android:name="android.intent.action.MAIN" /> < category android:name="android.intent.category.LAUNCHER" /> < /intent-filter> < /activity> < /application> < uses-sdk android:minSdkVersion="3" /> < /manifest>  

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

看完上述内容,你们掌握Android HelloWord编写方式是什么的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×