本项目提供了 Android 中按钮的 SVG (vectorDrawable) 支持,可以支持在 Android 5.0 以下使用 SVG 图片和 Tint 着色方案。
1.添加JitPack仓库
repositories {
maven {
url "https://jitpack.io"
}
}
2.添加依赖
implementation 'com.github.tianzhijiexian:SelectorInjection:Latest Latest release (click it)'
原则上是将原本android:
前缀变成app:
就可以支持 SVG (vectorDrawable) 和 Tint 了,下面是自定义控件和其支持属性的介绍:
SelectorTextView:
app:drawableLeft="@drawable/icon_facebook_svg"
app:drawableLeftTint="@color/red"
属性格式:
- drawable(Top/Left/Right/Bottom)
- drawable(Top/Left/Right/Bottom)Tint
SelectorImageButton:
app:src="@drawable/icon_facebook_svg"
android:tint="@color/orange"
SelectorRadioButton:
app:button="@drawable/icon_renren_svg"
app:buttonTint="@color/red"
注:对于单选按钮的SVG和Tint支持
View | Explain | Attribute |
---|---|---|
SelectorTextView | app:drawableBottom="@drawable/icon_facebook_svg" app:drawableBottomTint="@color/green" |
|
SelectorImageButton | app:src="@drawable/icon_robot_svg" android:tint="@color/orange" |
|
SelectorRadioButton | app:button="@drawable/icon_check_selector" app:buttonTint="@color/orange" |
Jack Tony: [email protected]
Copyright 2016-2019 Jack Tony
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.