AppCompat包的样式资源

资源定义

样式定义

com.android.support:appcompat-v7库中,样式主要的定义在$SDK_HOME/extras/android/v7/appcompat/res/values/themes_base.xml中,其中定义了如下样式:android

  • Platform.AppCompat(android:Theme)app

  • Platform.AppCompat.Light(Platform.AppCompat)code

  • Base.V7.Theme.AppCompat(Platform.AppCompat)orm

  • Base.V7.Theme.AppCompat.Light(Platform.AppCompat.Light)xml

  • Base.Theme.AppCompat(Base.V7.Theme.AppCompat)图片

  • Base.Theme.AppCompat.Light(Base.V7.Theme.AppCompat.Light)资源

  • 其余如.DarkActionBar等衍生样式get

其中对于若干的样式定义,好比it

  • editTextBackgroundio

  • 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>

其中资源是你新复制修改的资源,便可。

相关文章
相关标签/搜索