select---定义在drawable文件夹中的XML文件
发布时间:2020-12-16 05:18:18 所属栏目:百科 来源:网络整理
导读:获取Drawable对象: Resources res = mContext.getResources();Drawable myImage = res.getDrawable(R.drawable.my_image); selector 是在文件夹 drawable 中进行定义的xml文件。 它主要定义控件在下 pressed,selected,focused 及平常状态下的属性。 越前
获取Drawable对象: Resources res = mContext.getResources(); Drawable myImage = res.getDrawable(R.drawable.my_image); selector是在文件夹drawable中进行定义的xml文件。
越前面定义的状态,其优先级越高。对定得某个状态,如果某个属性没有显示说明,则表示此时该属性为任意值,都没关系。
示例1:
定义背景图片 bg_selector.xml文件 <?xmlversion="1.0"encoding="utf-8"?> < selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed =" true " android:drawable =" @drawable/listlayoutsample12xml_press_image "/> <item android:state_selected="true" android:drawable="@drawable/listlayoutsample12xml_focus_image"/> <item android:state_focused="true" android:drawable="@drawable/listlayoutsample12xml_focus_image"/> <item android:drawable="@drawable/listlayoutsample12xml_bg_image"/> </selector> 在布局文件中使用它 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:orientation="vertical" android: background =" @drawable/ bg_selector " android:paddingRight="13.33dp" android:layout_height="65.33dp" android:paddingLeft="31.9dp" android:gravity="center_vertical"> </LinearLayout> 示例2:
定义selector的颜色
<?xmlversion="1.0"encoding="UTF-8"?> <selectorxmlns:android="http://schemas.android.com/apk/res/android"> <itemandroid:state_pressed="true"android:color="@touchwiz:color/tw_color001"/> <itemandroid:state_selected="true"android:color="@touchwiz:color/tw_color001"/> <itemandroid:state_focused="true"android:color="@touchwiz:color/tw_color001"/> <itemandroid:color="@touchwiz:color/tw_color003"/> </selector>
//---------------------------------------
正常情况下,我们开发的应用程序都会上占满整个屏幕,那么怎么样才能开发出自定义窗口大小的的程序呢?如下图所示:
实现起来非常简单。 第一步,创建一个背景配置文件float_box.xml,放到res/drawable下,如下所示(如看不懂可查看本站:):
第二步,定义一个对话框样式,放到res/values/styles.xml,如下所示: <!--Copyright(C)2010IdeasAndroid
第三步,创建一个视图配置文件res/layout/float_activity.xml,一个ImageView和一个TextView,如下所示: <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
第四步创建我们的Activity,如下所示:
Java代码
最后一步,更改应用程序配置文件AndroidManifest.xml,将我们刚才创建的样式应用到我们的Activity上,如下所示: <activityandroid:name=".FloatActivityDemo"android:theme="@style/Theme.FloatActivity">
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |