栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

android MD风格组件(TextInputLayout AutoCompleteTextView MaterialButton SwitchMaterial MaterialRadio)(二)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

android MD风格组件(TextInputLayout AutoCompleteTextView MaterialButton SwitchMaterial MaterialRadio)(二)

android material design风格组件TextInputLayout,MaterialButton,SwitchMaterial,MaterialRadio

基本使用app:endIconMode 模式前置与后置其他常用操作可下拉选择的TextInputLayout配合 AutoCompleteTextView使用OhtermaterialRadioButtonMaterialCheckBox

自定义按钮:自定义background SwitchMaterial

相关文章:

MaterialButton,MaterialButtonToggleGroup,Chip,ChipGroup(一) [material环境配置,必看!]

今日完成效果:

效果一效果二效果三
基本使用


     
 

app:endIconMode 模式

 
    
     
 

app:endIconMode end模式startIcon 图标startIconTint start色调endIcon图标endIconTint end色调

效果图:

passwordclearcustom(自定义)
TextInputLayout#endIconMode="password_toggle"
TextInputEditText#inputType=“numberPassword”
TextInputEditText#endIconMode=“clear_text”TextInputEditText#endIconMode=“custom”
前置与后置


     
     
 

app:prefixText 前置图标app:prefixTextColor 前置图标颜色app:suffixText 后置图标app:suffixTextColor 后置图标颜色 其他常用操作



    

boxStrokeErrorColor 输入错误颜色 [默认红色]counterEnabled 计数器是否启动counterMaxLength 计数器最大值errorEnabled 错误检测启动placeholderText 占位符helperTextEnabled 帮助文字是否启动
动态代码:

 binding.errorEditText.doOnTextChanged { text, start, count, after ->
            if (text?.length!! >= 11) {
                binding.errorTextInput.error = "动态代码设置.错误信息"
                binding.errorEditText.error = "只能输入11位"
            } else {
                binding.errorTextInput.error = null
            }
            binding.errorTextInput.errorIconDrawable = null
        }

doonTextChanged() 监听变化

可下拉选择的


     
 

动态设置数据:

val items =
            listOf(
                "Material",
                "Design",
                "Components",
                "Android",
                "kotlin",
                "java",
                "ios",
                "c",
                "c++",
                "js",
                "python"
            )
        val adapter = ArrayAdapter(this, R.layout.list_item, items)
        binding.autoText.setAdapter(adapter)

list_item.xml:


其他样式:

Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu 弹出输入框Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu 不弹出输入框Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu 不弹出输入框2

弹出输入框不弹出输入框不弹出输入框2
TextInputLayout配合 AutoCompleteTextView使用

tips: AutoCompleteTextView 继承自EditText


            
            
        

动态代码:

val items =
            listOf(
                "Material",
                "Design",
                "Components",
                "Android",
                "kotlin",
                "java",
                "ios",
                "c",
                "c++",
                "js",
                "python"
            )
        val adapter = ArrayAdapter(this, R.layout.list_item, items)
        binding.autoText.setAdapter(adapter)

        // 设置AutoCompleteTextView.pop背景
        binding.autoText.setDropDownBackgroundResource(R.drawable.ic_emoji_06)

android:dropDownHeight 设置下拉高度

android:completionHint 提示语

android:dropDownWidth 弹出pop的宽

android:dropDownHeight 弹出pop的高

android:inputType 允许输入类型

android:dropDownHorizontalOffset 距离水平的位置

android:dropDownVerticalOffset 距离垂直侧的位置

android:dropDownSelector 选中时候的背景

效果图:


注意:这里设置背景一定要谨慎使用:

android:dropDownSelector="@drawable/ic_emoji_09" // 回收时候展示的图片

android:popupBackground="@drawable/ic_emoji_05" // 不起作用需要动态设置代码
binding.autoText.setDropDownBackgroundResource(R.drawable.ic_emoji_06) // 动态代码替换

bug分析:
当第一次进入的时候,如果弹出的软键盘和pop重叠的时候,会显示不了图片,可能显示图片了只是刷新掉了,众所周知,软键盘和弹出的pop都是一个window,我猜测可能是这里是配没有适配全,来看两张图就懂了!

bug复现理想状态

可以看出,只要是人写的代码,或多或少存在一定的毛病(偷笑)

Ohter

还有一些其他主题和风格一起看看吧!



     
 

@style/CutTheme2:


这个上一章说过就不重复提了

materialRadioButton

MaterialRadioButton貌似没有什么变化,目前还没有看出来… 拿常用的方法看看就可以了!



     
     

     

     

     
 

MaterialCheckBox

materialCheckBox和CheckBox好像也是相差无几,那就介绍几种自定义的方法吧

自定义按钮:

button 设置按钮状态app:useMaterialThemeColors=“false” 自定义颜色

自定义选择器:
@drawable/check_box_material_select:




    
    

效果图:

自定义background

android:button="@null" 隐藏按钮

自定义选中效果:
@drawable/switch_material_select:



    
    

打开时,switch_material_open.xml:



    
    
    

关闭时,switch_material_clone.xml:



    
    
    

效果:

SwitchMaterial

switchMaterial比较简单,直接看所有属性了!


android:textOff [checked=false help文字]android:textOn [checked=true help文字]app:showText [显示help文字]app:switchMinWidth [文字宽度]app:switchPadding [文字和switch的距离]app:switchTextAppearance 自定义样式android:typeface 设置字体app:thumbTint 按钮颜色app:trackTint 轨道颜色[可配合app:trackTintMode]app:track 自定义颜色/背景

来看看效果吧:


完整代码

相关文章:

MaterialButton,MaterialButtonToggleGroup,Chip,ChipGroup(一) [material环境配置,必看!]

原创不易,您的点赞就是对我最大的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/713104.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号