K.R*_*.R. 7 android switchcompat
我正在使用Android Studio并在我的主要活动中有一个SwitchCompat小部件.它的默认fontfamily是sans-serif-medium,我把它改成了quicksand_light.我还有一些TextViews,每个fontfamily都设置为quicksand_light.在我的活动的xml文件的设计选项卡上,它显示了具有quicksand_light fontfamily的SwitchCompat,就像TextViews一样,但是当我在手机或模拟器上运行它时,SwitchCompat的fontfamily是sans-serif-medium.有什么额外的东西我需要做更改fontfamily或这是一个错误或这只是我?
我还没有深入探讨为什么fontFamily在 xml 中定义属性时它不能正常工作,但如果您以编程方式设置字体,它就可以工作。
这是使用数据绑定的示例。
添加以下数据绑定适配器:
@BindingAdapter("labelTypeface")
fun setLabelTypeface(view: SwitchCompat, @FontRes id: Int) {
view.typeface = ResourcesCompat.getFont(view.context, id)
}
Run Code Online (Sandbox Code Playgroud)
并在您的布局中使用它:
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:labelTypeface="@{R.font.stratum}"
... />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
546 次 |
| 最近记录: |