您好,登錄后才能下訂單哦!
Android HelloWord編寫方式是什么,相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
相信學(xué)過編程的人員都對各種語言的helloword程序的編寫方式記憶猶新吧。在這里我們就為大家詳細(xì)介紹一下有關(guān)Android HelloWord的編寫方式,方便大家對這一操作系統(tǒng)編寫方式的理解。
Android多媒體播放功能的代碼解析
Android選項(xiàng)卡具體代碼編寫方式介紹
Android常用技巧編寫方式總結(jié)
Android特點(diǎn)總結(jié)介紹
Android內(nèi)核相關(guān)內(nèi)容總結(jié)
先說說整個(gè)程序要做哪些內(nèi)容吧,簡單helloword 通過一個(gè)按鈕點(diǎn)擊在另一個(gè)acitvity出現(xiàn)文本Hello xiaoshengDAI
說下Android HelloWord做的步驟吧:
1.首先新建項(xiàng)目,我這邊主要是測試Layout所以項(xiàng)目名就叫這個(gè)了。
2.我們要顯示一個(gè)按鈕,難后點(diǎn)擊這個(gè)按鈕就轉(zhuǎn)到其他activity顯示Hello xiaoshengDAI,新建類Layout主要來顯示***個(gè)activity即button,
1).在main.xml文件中進(jìn)行配置
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="來點(diǎn)我吧"/>
< /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="來點(diǎn)我吧"/>
< /LinearLayout>
2).設(shè)置監(jiān)聽和跳轉(zhuǎn)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進(jìn)行配置,將新建Activity配置文件加進(jìn)來
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可以運(yùn)行了,嘿嘿
看完上述內(nèi)容,你們掌握Android HelloWord編寫方式是什么的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。