Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the way Android HelloWord is written?

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

What is the way Android HelloWord is written? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

I believe that people who have studied programming are still fresh in their memory of the way helloword programs are written in various languages. Here we will introduce you in detail about the way Android HelloWord is written to facilitate your understanding of the way this operating system is written.

Code Analysis of Android Multimedia playback function

Introduction to the specific code writing method of Android tab

Summary of writing methods of common skills in Android

Summary and introduction of Android characteristics

Summary of related contents of Android Kernel

Let's first talk about what the whole program is going to do. Simple helloword displays the text Hello xiaoshengDAI in another acitvity by clicking a button.

Let's talk about the steps Android HelloWord does:

1. First of all, build a new project, my side is mainly to test Layout, so this is the name of the project.

two。 We need to display a button. When we click this button, we will go to another activity to display Hello xiaoshengDAI. The new class Layout is mainly used to display * activity or button.

1)。 Configure in the main.xml file

Java code

< ?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)。 Set up monitoring and redirecting actiovity

Java code

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. In Android HelloWord writing, create a new activityFrameLayout class and activityFrameLayout.xml file

Java code

< ?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 code

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. Configure AndroidManifest.xml to add the new Activity configuration file

Java code for Android HelloWord

< ?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 is ready to run. Hey, hey.

After reading the above, have you mastered how to write Android HelloWord? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report