android AppCompatEditText 样式(线条粗细等)修改
2016-08-02 15:46
465 查看
样式定义
com.android.support:appcompat-v7库中,样式主要的定义在$SDK_HOME/extras/android/v7/appcompat/res/values/themes_base.xml中,其中定义了以下样式:Platform.AppCompat(android:Theme)
Platform.AppCompat.Light(Platform.AppCompat)
Base.V7.Theme.AppCompat(Platform.AppCompat)
Base.V7.Theme.AppCompat.Light(Platform.AppCompat.Light)
Base.Theme.AppCompat(Base.V7.Theme.AppCompat)
Base.Theme.AppCompat.Light(Base.V7.Theme.AppCompat.Light)
其他如.DarkActionBar等衍生样式
其中对于若干的样式定义,比如
editTextBackground
editTextColor
……
其中定义了AppCompat包的各种样式。对于希望修改默认样式的,可以在当前Activity的样式中对需要修改的样式进行覆盖即可。比如,android.support.v7.widget.AppCompatEditText,在激活状态下下划线是加粗的,通过查看AppCompatEdit代码,找到其背景是@drawable\abc_edit_text_material,此文件是一个xml资源文件,定义了一个inset集合,使用了两张9patch图片,通过TintManager对其进行染色,就得到了所见的默认样式。
如果需要修改,比如将其激活状态下也改为同样粗细的下划线,可以新建(复制)一份@drawable\abc_edit_text_material文件,其默认内容为:
<inset xmlns:android="http://schemas.android.com/apk/res/android" android:insetLeft="@dimen/abc_edit_text_inset_horizontal_material" android:insetRight="@dimen/abc_edit_text_inset_horizontal_material" android:insetTop="@dimen/abc_edit_text_inset_top_material" android:insetBottom="@dimen/abc_edit_text_inset_bottom_material"> <selector> <item android:state_enabled="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/> <item android:state_pressed="false" android:state_focused="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/> <item android:drawable="@drawable/abc_textfield_activated_mtrl_alpha"/> </selector> </inset>
可以看到在最下方是使用了@drawable/abc_textfield_activated_mtrl_alpha资源,将其改为同上的资源,在样式文件中添加
<item name="editTextBackground">@drawable/abc_edit_text_material</item>
其中资源是你新复制修改的资源,即可。
如修改AppCompatEditText焦点时的线条粗细:
drawable下新建:
abc_edit_text_material.xml
<?xml version="1.0" encoding="utf-8"?> <inset xmlns:android="http://schemas.android.com/apk/res/android" android:insetLeft="@dimen/abc_edit_text_inset_horizontal_material" android:insetRight="@dimen/abc_edit_text_inset_horizontal_material" android:insetTop="@dimen/abc_edit_text_inset_top_material" android:insetBottom="@dimen/abc_edit_text_inset_bottom_material"> <selector> <item android:state_enabled="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/> <item android:state_pressed="false" android:state_focused="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/> <item android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/> </selector> </inset>
相关文章推荐
- Android 修改App中默认TextView的字体和颜色
- 如何修改Android App的样式风格
- 【Android---项目中】TextView设置字体样式及粗细
- Android 修改TextView字体样式
- 对Android APP的各种样式统一修改方法(这里列举了通知状态栏StatueBar,标题栏ActionBar,ToolBar和按钮Button的样式修改)
- Android TextView修改文字样式
- android AppCompatEditText 自定义下划线颜色
- Android Textview和Edittext文本选中样式修改实战
- 太激动!Android修改全局字体样式,替换整个APP字体
- 修改Android App样式风格的方法
- Android TextView修改文字样式
- Android客户端之“微服私访”App的系统学习(七)XRecyclerView快速实现列表界面+自定义Search输入框,软键盘搜索按钮监听+TextView部分样式改变
- Android的TextView使用Html来处理图片显示、字体样式、超链接等
- Android的TextView使用Html来处理图片显示、字体样式、超链接等
- Android的TextView/EditText使用CharacterStyle&SpannableString来处理图片显示、字体样式、超链接等
- Android 修改App的包名
- Android 自定义AlertDialog并通过AlertDialog修改TextView的值
- Android的TextView使用Html来处理图片显示、字体样式、超链接等
- Android 如何修改默认的Tab样式
- Android Actionbar学习笔记(三)-----修改Actionbar的样式