Android | Android应用程序文件结构

了解Android Studio文件结构的基础知识非常重要。为了便于理解Android studio工作环境,本文将介绍一些重要的文件/文件夹及其意义。

null

在下图中,标记了几个重要文件: Android Studio

上图中标记的所有文件简要说明如下:

  1. AndroidManifest。xml :Android中的每个项目都包含一个清单文件 AndroidManifest。xml ,存储在其项目层次结构的根目录中。清单文件是我们应用程序的重要组成部分,因为它定义了我们应用程序的结构和元数据、组件及其需求。

    该文件包括制作应用程序的每个活动、服务、内容提供商和广播接收器的节点,并使用意图过滤器和权限确定它们如何相互协调以及其他应用程序。

    一个典型的雄虫。xml文件如下所示:

    <? xml version = "1.0" encoding = "utf-8" ?>
    < manifest xmlns:android = " http://schemas.android.com/apk/res/android "
    package = "com.example.geeksforgeeks.geeksforgeeks" >
    < application
    android:allowBackup = "true"
    android:icon = "@mipmap/ic_launcher"
    android:label = "@string/app_name"
    android:roundIcon = "@mipmap/ic_launcher_round"
    android:supportsRtl = "true"
    android:theme = "@style/AppTheme" >
    < activity android:name = ".MainActivity" >
    < intent-filter >
    < action android:name = "android.intent.action.MAIN" />
    < category android:name = "android.intent.category.LAUNCHER" />
    </ intent-filter >
    </ activity >
    </ application >
    </ manifest >

    
    

  2. JAVA :Java文件夹包含Java源代码文件。这些文件用作受控UI(布局文件)的控制器。它从布局文件中获取数据,经过处理后,数据输出将显示在UI布局中。它在Android应用程序的后端工作。
  3. 可拖动 :可绘制文件夹包含资源类型文件(可以绘制的内容)。Drawables可以使用多种文件,如位图(PNG、JPEG)、九块补丁、向量(XML)、形状、层、状态、级别和比例。
  4. 布局 :布局定义用户界面的视觉结构,例如Android应用程序的UI。此文件夹存储用XML语言编写的布局文件。您可以添加其他布局对象或小部件作为子元素,以逐步构建定义布局文件的视图层次结构。

    下面是一个布局文件示例:

    <? xml version = "1.0" encoding = "utf-8" ?>
    < LinearLayout xmlns:android = " http://schemas.android.com/apk/res/android "
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:orientation = "vertical" >
    < TextView android:id = "@+id/text"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:text = "Hello, I am a TextView" />
    < Button android:id = "@+id/button"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:text = "Hello, I am a Button" />
    </ LinearLayout >

    
    

  5. 纹理映射 :Mipmap文件夹包含可在Android Studio应用程序中使用的图像资产文件。您可以生成以下图标类型,如启动器图标、操作栏和选项卡图标以及通知图标。
  6. 颜色。xml :颜色。xml文件包含Android应用程序的颜色资源。不同的颜色值由可在Android应用程序中使用的唯一名称标识。

    下面是颜色示例。xml文件:

    <? xml version = "1.0" encoding = "utf-8" ?>
    < resources >
    < color name = "colorPrimary" >#3F51B5</ color >
    < color name = "colorPrimaryDark" >#303F9F</ color >
    < color name = "colorAccent" >#FF4081</ color >
    </ resources >

    
    

  7. 串。xml :琴弦。xml文件包含Android应用程序的字符串资源。不同的字符串值由可在Android应用程序中使用的唯一名称标识。该文件还使用XML语言存储字符串数组。

    下面是颜色示例。xml文件:

    < resources >
    < string name = "app_name" >GeeksforGeeks</ string >
    </ resources >

    
    

  8. 风格。xml :风格。xml文件包含Android应用程序中主题样式的资源。这个文件是用XML语言编写的。

    下面是一个示例样式。xml文件:

    < resources >
    <!-- Base application theme. -->
    < style name = "AppTheme" parent = "Theme.AppCompat.Light.DarkActionBar" >
    <!-- Customize your theme here. -->
    < item name = "colorPrimary" >@color/colorPrimary</ item >
    < item name = "colorPrimaryDark" >@color/colorPrimaryDark</ item >
    < item name = "colorAccent" >@color/colorAccent</ item >
    </ style >
    </ resources >

    
    

  9. 建筑gradle(模块:应用程序) :这定义了特定于模块的构建配置。在这里,您可以在Android应用程序中添加所需的依赖项。

    apply plugin: 'com.android.application'
    android {
    compileSdkVersion 26
    defaultConfig {
    applicationId "com.example.geeksforgeeks.geeksforgeeks"
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    }
    }
    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:0.5'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
    }

    
    

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享