• Android学习——day3


    项目中的资源

    res目录

    • 以drawable开头的文件用来放图片

    • 以mipmap开头的文件存放应用图标

    • 以values开头的文件夹存放字符串、样式、颜色等配置

    • layout文件夹存放布局文件

    1.说明

    drawable/mipmap-hdpi、drawable/mipmap-mdpi、drawable/mipmap-xhdpi、drawable/mipmap-xxhdpi、drawable/mipmap-xxhdpi里面存放不同分辨率的图片,程序运行时,自动根据当前运行设备分辨率高低选择加载哪个文件夹下的图片 ;如只有一张图片,可以放在drawable-xxhdpi文件夹下。


    2.引用的基本语法

    • 在代码中通过R.string.hello_world可以获得字符串的引用

    • 在XML中通过@string/hello_world可以获得字符串的引用

         其中string可以替换为drawable、mipmap或layout。


    3.例子

    在AndroidManifest.xml文件中

     1 <application
     2     android:allowBackup="true"
     3     android:icon="@mipmap/ic_launcher"
     4     android:label="@string/app_name"
     5     android:supportsRtl="true"
     6     android:theme="@style/AppTheme">
     7     <activity android:name=".HelloWorldActivity">
     8         <intent-filter>
     9             <action android:name="android.intent.action.MAIN" />
    10             <category android:name="android.intent.category.LAUNCHER" />
    11         </intent-filter>
    12     </activity>
    13 </application>
    •   android:icon="@mipmap/ic_launcher":指定了应用图标

    •   android:label="@string/app_name":指定了应用名称

    此后可以自行更改应用名称、文本内容等

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     3     package="com.example.a86147.helloworld">
     4 
     5     <application
     6         android:allowBackup="true"
     7         android:icon="@mipmap/ic_launcher"
     8         android:label="@string/app_name"
     9         android:supportsRtl="true"
    10         android:theme="@style/AppTheme">
    11         <activity android:name=".HelloWorldActivity">
    12             <intent-filter>
    13                 <action android:name="android.intent.action.MAIN" />
    14 
    15                 <category android:name="android.intent.category.LAUNCHER" />
    16             </intent-filter>
    17         </activity>
    18     </application>
    19 
    20 </manifest>

     

  • 相关阅读:
    ffplay.c函数结构简单分析(绘图)
    SNMP安全配置的两种方法(也可同一时候兼顾配置两种方法)
    LINKs: Xamarin.Forms + Prism
    Linux目录详解
    搜狗输入法 for Linux v2.2.0.0108
    centos 查看IP
    CentOS安装系统时硬盘分区建议
    CentOS 7 各个版本的区别
    VMware安装Centos7超详细过程(图文)
    Centos7从零开始】Centos 下硬盘分区的最佳方案
  • 原文地址:https://www.cnblogs.com/znjy/p/14279910.html
Copyright © 2020-2023  润新知