Android 笔记2

来源:互联网 发布:淘宝号有订单信用清洗 编辑:程序博客网 时间:2024/04/28 17:16



可以在资源文件中定义颜色资源尺寸资源字符串资源。这几个一般都放在/res/values下。颜色常用colors.xml,字符串常在strings.xml中,尺寸在dimens.xml中。在mian.xml中可以引用定义的资源。在程序中也可以引用资源。获得数字资源用

Strings texts[] = getResources().getStringArray(R.array.string_arr);


如果是Drawable数组使用方法为:

TypedArray icons = resources.obtainTypedArray(R.array.plain_arr);textView.setBackgroundDrawable(icons.getDrawable(position));

Drawable数组的定义方法为:/res/values/arrays.xml

<!-- 定义一个Drawable数组 -->    <array name="plain_arr">        <item>@color/c1</item>        <item>@color/c2</item>        <item>@color/c3</item>        <item>@color/c4</item>        <item>@color/c5</item>        <item>@color/c6</item>        <item>@color/c7</item>        <item>@color/c8</item>        <item>@color/c9</item>    </array>



drawable是绘制资源类型。下面又分为很多比如ClipDrawable,StateListDrawable

有时候Android有一些应用配置信息需要保存,推荐使用xml文件保存,一般在res/xml下。

定义:

没有特殊要求只要是格式符合xml格式即可。

访问:

xml文件中访问用@[<packagename>:]xml/filename

如果:string s1=new String("Hello");string s2=new String("Hello");则(s1==s2)=false如果:string s1="Hello";string s2="Hello";则(s1==s2)=true;因为他们指向的同一个对象


<resources xmlns:android="http://schemas.android.com/apk/res/android">    <!-- 定义一个样式,指定字体大小颜色 -->    <style name="style1">        <item name="android:textSize">20sp</item>        <item name="android:textColor">#00d</item>    </style>    <!-- 定义一个样式,继承前一个颜色 -->    <style name="style2" parent="@style/style1">        <item name="android:background">#ee6</item>        <item name="android:padding">8dp</item>        <!-- 覆盖父样式中的属性 -->        <item name="android:textColor">#000</item>    </style></resources>


0 0
原创粉丝点击