我有一個按鈕,并且字母間距不起作用。請檢查我的以下內容snippet code
<style name="ButtonText_v2" parent="TextAppearance.AppCompat">
<item name="fontFamily">@font/silka_regular</item>
<item name="android:letterSpacing">0.1</item>
<item name="android:textSize">@dimen/dimen_14dp</item>
</style>
<style name="PrimaryButton_v2" parent="Widget.AppCompat.Button">
<item name="android:background">@drawable/button_selector_primary</item>
<item name="android:textColor">@color/white</item>
<item name="textAllCaps">true</item>
<item name="textAppearance">@style/ButtonText_v2</item>
</style>
layout.xml 檔案
<Button
android:text="Button"
android:layout_height="56dp"
android:layout_width="200dp"
style="@style/PrimaryButton_v2"
android:layout_margin="15dp"
/>
uj5u.com熱心網友回復:
您不能在按鈕/自定義按鈕中應用字母間距,因為它們在按鈕組件中存在一些限制,您無法進行文本外觀和背景自定義以及更多限制,對此的解決方案是您可以使用文本視圖而不是按鈕來制作自定義文本視圖它也將類似于按鈕并根據需要對其進行自定義。例如:- https://stackoverflow.com/questions/9477336/how-to-make-a-custom-textview#:~:text=Create a Custom View for Textview. Make the, values Make entries of all fonts in strings.xml
uj5u.com熱心網友回復:
添加 android:letterSpacing在PrimaryButton_v2它將很好地作業。
<style name="ButtonText_v2" parent="TextAppearance.AppCompat">
<item name="fontFamily">@font/silka_regular</item>
<item name="android:textSize">@dimen/dimen_14dp</item>
</style>
<style name="PrimaryButton_v2" parent="Widget.AppCompat.Button">
<item name="android:background">@drawable/button_selector_primary</item>
<item name="android:textColor">@color/white</item>
<item name="textAllCaps">true</item>
<item name="textAppearance">@style/ButtonText_v2</item>
<item name="android:letterSpacing">0.1</item>
</style>
layout.xml 檔案
<Button
android:text="Button"
android:layout_height="56dp"
android:layout_width="200dp"
style="@style/PrimaryButton_v2"
android:layout_margin="15dp"
/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/357540.html
