深入了解HelloAndroid下的三个文件

Home / Android MrLee 2016-9-28 3144

下面列出我们要掌握的几个重要文件


深入了解HelloAndroid下的三个文件——转载出处:coder-pig



HelloAndroid.java:


代码如下:

[java] view
plaincopy

深入了解HelloAndroid下的三个文件——转载出处:coder-pig

深入了解HelloAndroid下的三个文件——转载出处:coder-pig

  1. import android.os.Bundle;  
  2. import android.app.Activity;  
  3.   
  4.   
  5. public class MainActivity extends Activity {  
  6.   
  7.     @Override  
  8.     protected void onCreate(Bundle savedInstanceState) {  
  9.         super.onCreate(savedInstanceState);  
  10.         setContentView(R.layout.activity_main);  
  11.     }  
  12. }  


代码解析:

深入了解HelloAndroid下的三个文件——转载出处:coder-pig






布局文件main.xml

代码如下:


[html] view
plaincopy

深入了解HelloAndroid下的三个文件——转载出处:coder-pig

深入了解HelloAndroid下的三个文件——转载出处:coder-pig

  1. <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical"  
  6.     tools:context=".MyActivity">  
  7.   
  8.     <TextView  
  9.         android:text="@string/hello_world"  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content" />  
  12.   
  13. </LinearLayout></span>  



代码解释:

我们定义了一个LinearLayout线性布局

在xml命名空间中定义我们所需要使用的架构,来自于①

深入了解HelloAndroid下的三个文件——转载出处:coder-pig





AndroidManifest.xml配置文件:

代码如下:

[html] view
plaincopy

深入了解HelloAndroid下的三个文件——转载出处:coder-pig

深入了解HelloAndroid下的三个文件——转载出处:coder-pig

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="example.jay.com.myfirstapplication"  
  4.     android:versionCode="1"  
  5.     android:versionName="1.0" >  
  6.   
  7.     <uses-sdk  
  8.         android:minSdkVersion="8"  
  9.         android:targetSdkVersion="21" />  
  10.   
  11.     <application  
  12.         android:allowBackup="true"  
  13.         android:icon="@drawable/ic_launcher"  
  14.         android:label="@string/app_name"  
  15.         android:theme="@style/AppTheme" >  
  16.         <activity  
  17.             android:name=".MainActivity"  
  18.             android:label="@string/app_name" >  
  19.             <intent-filter>  
  20.                 <action android:name="android.intent.action.MAIN" />  
  21.   
  22.                 <category android:name="android.intent.category.LAUNCHER" />  
  23.             </intent-filter>  
  24.         </activity>  
  25.     </application>  
  26.   
  27. </manifest><strong>  
  28. </strong>  



代码解释:

深入了解HelloAndroid下的三个文件——转载出处:coder-pig


除了上述的内容外,

①如果app包含其他组件的话,都要使用类型说明语法在该文件中进行声明

Server:<server>元素     BroadcastReceiver<receiver>元素     ContentProvider<provider>元素

IntentFilter<intent-filter>元素


②权限的声明:

在该文件中显式地声明程序需要的权限,防止app错误地使用服务,  不恰当地访问

资源,最终提高android app的健壮性

android.permission.SEND_SMS 有这句话表示app需要使用发送信息的权限,安装的时候就会提示用户,

相关权限可以在sdk参考手册查找


本文链接:https://www.it72.com/10626.htm

推荐阅读
最新回复 (0)
返回