androidのSwitchコンポーネントへのフォントを変更したいのですが、指定しても変更されていません。
TextViewなど他のコンポーネントでは指定は効いています。
どこがおかしいのかご指摘いただけると幸いです。
androidのバージョンは5.0,6.0,7.0です。
activity_main.xml
1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 android:orientation="vertical" 5 android:layout_width="fill_parent" 6 android:layout_height="fill_parent" 7 android:gravity="center"> 8 9 <TextView 10 android:id="@+id/textView" 11 android:layout_width="fill_parent" 12 android:layout_height="wrap_content" 13 android:text="Hello World!" 14 app:fontFamily="@font/asset"/> 15 16 <Switch 17 android:id="@+id/switch1" 18 android:layout_width="fill_parent" 19 android:layout_height="wrap_content" 20 android:text="Switch" 21 app:fontFamily="@font/asset"/> 22 23</LinearLayout>
コードでの指定は有効でした。
Switch switch1 = findViewById(R.id.switch);
Typeface typeface = ResourcesCompat.getFont(this,R.asset);
switch1.setTypeface(typeface);
あなたの回答
tips
プレビュー