Values文件夹
· arrays.xml:定义数组数据;
· colors.xml:定义表示颜色的数据;
· dimens.xml:定义尺度,可以使用Resources.getDimension()获得这些资源;
· strings.xml:定义字符串,可以使用Resources.getString()或Resources.getText()方法获得这些资源;
· styles.xml:定义显示的样式文件;
dimens 主要定义文字大小sp,组件的height width
Styles 样式 如:Dialog的无标题 透明 什么 如:TextView的文字大小 宽高都可以
res /values /dimens.xml
<resources>
<dimen name="textSize_TextView">30sp</dimen>
<dimen name="width_EditText">400dp</dimen>
<dimen name="height_EditText">100dp</dimen>
</resources>
res /values /colors.xml
<resources>
<color name="blue">#3399cc</color>
<color name="red">#cc3300</color>
</resources>
res /values /styles.xml
<style name="editText_style">
<item name="android:textColor">@color/blue</item>
<item name="android:gravity">center</item>
<item name="android:text">"样式"</item>
<item name="android:textSize">18sp</item>
<item name="android:layout_height">200dp</item>
<item name="android:layout_width">500dp</item>
<item name="android:layout_margin">10dp</item>
</style>
main .xml
<!-- dimen和color的使用 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView textSize=30sp"
android:textSize="@dimen/textSize_TextView"
android:layout_margin="10dp"
/>
<EditText
android:layout_width="@dimen/width_EditText"
android:layout_height="@dimen/height_EditText"
android:hint="EditText width:500 height:200"
android:textColorHint="@color/red"
android:layout_margin="10dp"
/>
<!-- style和selector的使用 -->
<EditText
style="@style/editText_style"
android:background="@drawable/edittext_selector"
/>
main.xml中使用到的style样式 是在values文件夹下
而用到的background则是在drawable文件夹下
<selector /> <shape /> 这些都在drawable文件夹下
drawable文件夹
一般用来放置一些xml文件 如样式,常被android:background="@drawable/xxx"访问
drawable /bg_edittext_normal
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="3dp" />
<solid android:color="#FFFFFF" />
<stroke android:width="2dp"
android:color="#ffcc00"/>
</shape>
drawable /bg_edittext_focused
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="3dp"/>
<solid android:color="#FFFFFF"/>
<stroke android:width="2dp"
android:color="@color/blue" />
</shape>
drawable /edittext_selector
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="false" android:drawable="@drawable/bg_edittext_normal"></item>
<item android:state_focused="true" android:drawable="@drawable/bg_edittext_focused"></item>
</selector>
<!-- 上面写成android:background="@drawable/bg_edittext_normal" 编译通过 但一运行就退出
记住了 是 android:drawable 不是android:background -->
截图:
EditText获取焦点 通过selector 变色