自定义android EditText样式及使用方式

在Android开发中,为了满足特定需求,有时需要自定义EditText的样式。通过使用selector,可以实现获取焦点和失去焦点时不同的显示效果。具体实现包括在drawable目录下创建edit_selector.xml选择器文件,以及定义搜索框的普通状态和聚焦状态样式文件search_edittext_style.xml和search_edittext_style_focused.xml,使用layer-list来设置矩形框的填充颜色和边框宽度。
摘要由CSDN通过智能技术生成

开发中需要对EditText样式进行特殊化定义,使用selector进行获取焦点和失去焦点的样式设计:

代码实现:

searchText.setBackgroundResource(R.drawable.search_edit_selector);


所有的样式和selector都放在drawable目录;

edit_selector.xml书写方式:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">


    <item android:drawable="@drawable/search_edittext_style" android:state_window_focused="false"/>
    <item android:drawable="@drawable/search_edittext_style_focused" android:state_focused="true"/>


</selector>


search_edittext_style.xml样式书写,使用layer-list 实现:


<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android&

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值