使用selector可以实现在XML中动态改变布局:
(1)在res/drawable下定义一个文件advancedbutton.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/onfocusimage" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/clickimage" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/clickimage" />
<item android:drawable="@drawable/lostfocusimage" />
</selector>
(2)在布局文件main.xml中使用selector
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF25CCDD">
<ImageButton
android:id="@+id/image_Button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/advancedbutton"/>
<Button android:text="Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
具体示例见附件
分享到:
相关推荐
使用自定义命名空间.a => .prefix .a每个CSS选择器添加前缀。 目录 安装 $ npm install postcss-prefix-selector 与PostCSS结合使用 const prefixer = require ( 'postcss-prefix-selector' ) // css to be ...
Selector
Contact Selector在infopath中的使用!
要使用file_selector插件,首先需要将插件的依赖项添加到pubspec.yaml文件中,并运行flutter pub get命令获取插件的最新版本。 在插件使用方面,file_selector插件可以方便地实现文件选择功能,支持多选和所有类型...
请注意,从 0.3 版开始,XML Selector 使用它自己的基于的 DOM 实现。 这与之前的非标准文档界面不同。 XML Selector 当前实现了 DOM Level 1 的只读子集。这将在未来扩展以满足,至少,完整的 Level 1 支持。 我为...
Android自定义矩形及selector、shape的使用Android自定义矩形及selector、shape的使用
探索Android中selector和shape的结合使用
一个强大的selector注入器,它可以让view自动产生selector状态,免去了你写selector的麻烦。
Android selector 完整demo
selenium css selector 定位详解
在simulink上进行BusCreator和BusSelector的简单实验
带圆角的selector
CSS Selector 生成器
selectorgadget插件,R语言爬取网页
java selector 测试并发.多线程并发。
欢迎使用选择器 :waving_hand: Typescript中的通用选择器库正在安装使用npm: npm i --save selector 使用纱: yarn add --dev selector用法以下是有关如何使用selector示例。createSelector 返回选择器助手例子获取...
NULL 博文链接:https://flym.iteye.com/blog/392373
Laravel开发-selector 选择器模式抽象类,用于管理用户级或运行时参数上的多态性。
代码实现drawable的selector效果,不用为每个控件写selector样式; 另外,实现圆形图片处理、圆角图片处理功能
一个关于SocketChannel、ServerSocketChannel、Selector的综合案例