AutoMan实用教程-Selector用法
- 格式:pptx
- 大小:1.03 MB
- 文档页数:11


autoconfigurationimportselector 原理-回复AutoConfigurationImportSelector是Spring Boot中的一个关键组件,它用于根据应用程序的classpath(类路径)和条件规则来选择自动配置类。
在本文中,我将一步一步回答关于AutoConfigurationImportSelector的原理以及它如何工作的问题。
什么是自动配置?自动配置是Spring Boot的一个重要特性,它通过分析应用程序的类路径,自动配置一系列常见的框架和第三方库。
它的目标是减少开发者的工作量,使得创建可用于生产的应用程序变得更加容易。
自动配置是通过自动配置类实现的,这些类通常被放置在`META-INF/spring.factories`文件中。
当Spring Boot应用程序启动时,它会自动加载这些自动配置类,并根据条件规则来决定是否要应用它们。
AutoConfigurationImportSelector是什么?AutoConfigurationImportSelector是Spring Boot中自动配置的核心组件之一。
它是一个实现了ImportSelector接口的类,用于根据条件规则选择自动配置类。
在Spring启动过程中,当AutoConfigurationImportSelector被触发时,它会根据应用程序的类路径和条件规则来选择并导入相应的自动配置类。
AutoConfigurationImportSelector的工作原理1. 触发AutoConfigurationImportSelector自动配置的触发点通常是`EnableAutoConfiguration`注解。
当这个注解被应用于一个Spring Boot启动类时,它会触发AutoConfigurationImportSelector的执行。
2. 加载所有的自动配置类AutoConfigurationImportSelector会加载classpath(类路径)上所有的自动配置类。
uiautomator基础知识点-回复关于uiautomator基础知识点的一篇1500-2000字文章。
一、什么是uiautomator?uiautomator是Android官方提供的一个UI自动化测试框架,用于在Android设备上测试用户界面。
它可以模拟用户的输入操作,比如点击、滑动、输入文本等,并获取界面上的元素信息。
使用uiautomator 可以编写自动化测试脚本,对Android应用进行功能测试和回归测试,提高测试效率。
二、uiautomator的基本组成1. uiautomator.jar:该文件是uiautomator的核心库,包含了与设备交互的底层接口和方法。
2. uiautomatorviewer:是uiautomator的可视化工具,可以用于查看Android应用的UI布局结构,以及获取应用中的各种控件的属性和信息。
3. adb工具:uiautomator依赖于adb工具与设备进行通信。
三、安装uiautomator1. 下载Android SDK:前往Android官方网站下载并安装最新版本的Android SDK。
2. 配置环境变量:将Android SDK中的tools和platform-tools目录添加到系统的环境变量中。
3. 启动uiautomatorviewer:打开终端窗口,输入`uiautomatorviewer`命令,如果成功启动uiautomatorviewer工具,则表示uiautomator已经安装成功。
四、uiautomator的使用场景uiautomator主要适用于以下场景:1. 功能测试:uiautomator可以模拟用户的各种操作,对应用的各个功能进行全面的自动化测试。
2. 回归测试:当应用发生更新或修改时,可以使用uiautomator编写自动化脚本,对修改前后的应用进行比对测试,确保修改不会引入新的问题。
3. 批量测试:uiautomator可以批量运行测试用例,提高测试工作的效率。
Androidselector状态选择器的使⽤详解⼀、⽬的效果越好的⽤户体验来源更直接更明显的事件反馈。
selector可以“预存”多种响应的反馈,主要以下多种状态有:android:state_selected是选中android:state_focused是获得焦点android:state_pressed是点击android:state_enabled是设置是否响应事件,指所有事件设置不同状态的表现形式,则会在不同场景下有不同状态。
如⽂字:被选中状态,未被选中状态。
selector的普通使⽤则是为对应单个控件添加以selector为背景的资源,则能达到⽬的。
联合使⽤则是基本使⽤⼀种升级。
在我们的导航栏中,常使⽤LinearLayout或者RelativeLayout包含⼀个ImageView和⼀个TextView。
图⽚⽤于直观观感,⽂字⽤于更清晰的描述。
在⼀个整体菜单被选中时,需要图⽚及⽂字都表现对应的状态。
并为保证较⼤的事件响应范围,点击事件常赋予包含图⽚和⽂字的⽗控件。
即:为LinearLayout设置点击事件,ImageView、TextView表现对应的状态。
⼆、具体实现⽂字的selector:res添加⽬录color,res/color/bg_tv_selector.xml<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="/apk/res/android"><item android:color="@color/red" android:state_pressed="true" /><item android:color="@color/black" /></selector>图⽚的selector:bg_qq_iv_selector.xml<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="/apk/res/android"><item android:drawable="@mipmap/b_qq_pressed" android:state_pressed="true" /><item android:drawable="@mipmap/b_qq" /></selector>使⽤shape为Button的背景图,并设置selector:bg_bt_drawable_normal.xml:<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="/apk/res/android"><corners android:radius="10dp" /><strokeandroid:width="2dp"android:color="@color/black" /></shape>bg_bt_drawable_pressed.xml:<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="/apk/res/android"><corners android:radius="5dp" /><strokeandroid:width="2dp"android:color="@color/blue"android:dashGap="10dp" /><gradientandroid:centerColor="@color/red"android:endColor="@color/green" /></shape>bg_bt_selector.xml:<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="/apk/res/android"><item android:drawable="@drawable/bg_bt_drawable_pressed" android:state_pressed="true" /><item android:drawable="@drawable/bg_bt_drawable_normal" />activity_main.xml中使⽤:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android" xmlns:tools="/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="com.future.selectorlldemo.MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><LinearLayoutandroid:id="@+id/qq_ll"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:background="@color/green"android:clickable="true"android:gravity="center"android:orientation="vertical"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/bg_qq_iv_selector" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="QQ"android:textColor="@color/bg_tv_selector" /></LinearLayout><LinearLayoutandroid:id="@+id/weixin_ll"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:background="@color/blue"android:clickable="true"android:gravity="center"android:orientation="vertical"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/bg_weixin_iv_selector" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="WeChat"android:textColor="@color/bg_tv_selector" /></LinearLayout></LinearLayout><LinearLayoutandroid:id="@+id/text_button_ll"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="⽂字和Button"android:textColor="@color/bg_tv_selector" />android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:background="@drawable/bg_bt_selector"android:clickable="false"android:text="确认" /></LinearLayout></LinearLayout>MainActivity.Java中应⽤效果:public class MainActivity extends AppCompatActivity implements View.OnClickListener {/*** qq登录按钮*/private LinearLayout qqLoginLL;/*** 微信登录按钮*/private LinearLayout weixinLoginLL;/*** ⽂字和Button⼀起*/private LinearLayout textButtonLL;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.activity_main);qqLoginLL = (LinearLayout) findViewById(R.id.qq_ll);weixinLoginLL = (LinearLayout) findViewById(R.id.weixin_ll);textButtonLL = (LinearLayout) findViewById(R.id.text_button_ll);qqLoginLL.setOnClickListener(this);weixinLoginLL.setOnClickListener(this);textButtonLL.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.qq_ll:Toast.makeText(MainActivity.this, "你点击了QQ登录区间", Toast.LENGTH_SHORT).show();break;case R.id.weixin_ll:Toast.makeText(MainActivity.this, "你点击了WeChat登录区间", Toast.LENGTH_SHORT).show(); break;case R.id.text_button_ll:Toast.makeText(MainActivity.this, "你点击了Text_Button区间", Toast.LENGTH_SHORT).show(); break;}}}展⽰效果:三、注意细节1.默认状态放在selector的最后<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="/apk/res/android"><item android:drawable="@mipmap/b_qq" /><item android:drawable="@mipmap/b_qq_pressed" android:state_pressed="true" /></selector>不能实现对应效果2.TextView selector需要放置在 res/corlor⽬录下以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
android kotlin selector扩展函数-回复Android Kotlin Selector扩展函数:为UI控件设置状态选择器样式选择器(Selector)在Android中是一种常用的UI控件样式设置方式,可以根据控件的不同状态来显示不同的样式,例如按下、选中、禁用等状态。
在Kotlin中,我们可以通过自定义扩展函数来简化设置状态选择器样式的过程,提高代码的可读性和可维护性。
本文将一步一步地介绍如何使用Kotlin的扩展函数为Android控件设置状态选择器样式。
第一步:新建一个Selector.kt文件首先,我们需要创建一个名为Selector.kt的Kotlin文件,作为我们的扩展函数集合。
在该文件中,我们将定义几个扩展函数,用于为不同类型的控件设置不同状态下的样式。
第二步:实现扩展函数在Selector.kt文件中,我们可以定义多个扩展函数,分别用于设置不同类型控件的状态选择器样式。
例如,我们可以定义一个扩展函数用于为按钮控件设置样式:fun Button.setSelectorBackground(normalDrawable: Drawable?,pressedDrawable: Drawable?,disabledDrawable: Drawable?) {val selector = StateListDrawable().apply {addState(intArrayOf(android.R.attr.state_pressed), pressedDrawable)addState(intArrayOf(-android.R.attr.state_enabled), disabledDrawable)addState(intArrayOf(), normalDrawable)}this.background = selector}在setSelectorBackground函数中,我们使用StateListDrawable()创建一个状态选择器对象。