Android 笔记2
发布时间:2022-11-12 19:47:29 324 相关标签: # webkit# android# 信息
可以在资源文件中定义颜色资源尺寸资源字符串资源。这几个一般都放在/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
@color/c1
@color/c2
@color/c3
@color/c4
@color/c5
@color/c6
@color/c7
@color/c8
@color/c9
drawable是绘制资源类型。下面又分为很多比如ClipDrawable,StateListDrawable
有时候Android有一些应用配置信息需要保存,推荐使用xml文件保存,一般在res/xml下。
定义:
没有特殊要求只要是格式符合xml格式即可。
访问:
xml文件中访问用@[:]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>
文章来源: https://blog.51cto.com/u_13316945/5832048
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报