zoukankan      html  css  js  c++  java
  • 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>

     

  • 相关阅读:
    jdk和jre有什么区别?
    Apache的作用及意义
    博客园新成员的第一天
    重构改善既有代码的设计--简化条件表达式
    SourceMonitor: 代码重构的小工具,大用场
    使用Eclipse中提供的Refactor(重构)工具
    极大提高Web开发效率的8个工具和建议(含教程)
    Hbase shell命令
    Java多线程-新特性-有返回值的线程
    Java多线程-新特征-条件变量
  • 原文地址:https://www.cnblogs.com/znjy/p/14279910.html
Copyright © 2011-2022 走看看