Android的HelloWorld
来源:互联网 发布:王者荣耀mvp新算法 编辑:程序博客网 时间:2024/06/07 01:46
MainActivity.java
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
R.layout.activity_main是一个布局配置文件,ctrl点开可以看到如下:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".MainActivity" />
<AnalogClock
android:id="@+id/analogClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp" />
</RelativeLayout>
####可以通过在此文件的Graphic_layout视图中拖动元素来进行布局设计
@string/hello_world也是一个配置的xml文件,在里面配置一些字符串常量,ctrl点开如下:
<resources>
<string name="app_name">HelloWorld</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
在AVD中运行效果如下:
再看此工程的配置文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这里配置程序的基本信息,如默认运行的activity,activity的其他属性
android书籍推荐:《Android SDK 开发范例大全》余志龙等编著 /人民邮电出版社
- android的helloworld
- Android的helloworld程序
- 开始android的HelloWorld
- Android的HelloWorld
- Phonegap-Android的HelloWorld
- Android的HelloWorld
- android Phonegap项目的HelloWorld
- Android 4.4.2 的helloworld
- Android - HelloWorld的Layout内容
- [Android学习笔记一]Android的HelloWorld
- Android HelloWorld
- android helloworld
- Android helloworld
- android helloworld
- Android helloWorld
- Android HelloWorld
- Android--HelloWorld
- android helloworld
- 关于ics lab8 performance中的smooth
- 社交平台舆情分析项目的总结和感想(LU学习,EM,KNN)(二)
- ASP.NET页面运行机制
- poj1308 (并查集)Is It A Tree?
- ForSecondWork-No.1:C/C++笔试题回忆并整理
- Android的HelloWorld
- 表达式求值(nyoj305)
- n个小球t次跳出问题球的算法问题
- linux gbd 调试代码
- gcc常用命令
- 才高行厚的hibernate(7)---hibernate的优化
- __int64
- [LeetCode] Clone Graph
- jQuery列表拖动排列