[英]How to change the typeface of Chip view?
我想從設計支持庫更改芯片視圖的字體。 在我瀏覽它的源代碼后,我發現它是通過Paint直接在ChipDrawable中繪制文本的,我找不到任何更改字體的公共方法。 我應該如何嘗試更改芯片視圖字體? 請幫忙。 謝謝。
有點晚了,但如果有人仍然感興趣,我會發布我的解決方案。
首先使用您的自定義字體創建一個字體系列 xml。
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<font app:fontStyle="normal" app:fontWeight="400" app:font="@font/my_custom_font"/>
</font-family>
然后將芯片樣式添加到使用您的字體系列的樣式 xml:
<style name="chipText" parent="TextAppearance.MaterialComponents.Chip">
<item name="android:textSize">14sp</item>
<item name="android:fontFamily">@font/my_font_family</item>
</style>
然后,當您在 xml 中創建芯片視圖時,設置 textAppearance 屬性:
android:textAppearance="@style/chipText"
您的解決方案在正常芯片視圖中工作 - 在 TextInputLayout 中仍然存在一些問題芯片。 (字體不變)
注意:屏幕旋轉自定義字體后,我不知道為什么
實現“com.google.android.material:material:1.3.0-alpha01”
<com.google.android.material.textfield.TextInputLayout
android:layout_width="240dp"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_gravity="center"
android:textAppearance="@style/chipText"
android:hint="Text Field">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Text"
android:textAppearance="@style/chipText"/>
</com.google.android.material.textfield.TextInputLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.