Kel*_*iya 2 android preferencescreen typeface
我已经创建了嵌套的preferenceScreens.I想要添加自定义字体,preferenceScreen title and summary.我尝试使用加载到字体的字体.我怎样才能做到这一点?谢谢.
这是我的preference.xml:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/manage_device_title"
android:key="@string/device_category">
<PreferenceScreen android:title="@string/manage_device"
android:key="@string/manage_device_KEY"
android:summary="@string/device_summary" >
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
您需要创建CustomPreference并CustomPreferenceCategory为.包括那个CustomPreference和CustomPreferenceCategory你的preference.xml
CustomPreference:
public class CustomPreference extends Preference {
Typeface fontStyle;
public CustomPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CustomPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomPreference(Context context) {
super(context);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
fontStyle = Typeface.createFromAsset(CA.getApplication().getApplicationContext().getAssets(), AppConstants.fontStyle);
TextView titleView = (TextView) view.findViewById(android.R.id.title);
titleView.setTypeface(fontStyle);
titleView.setTextColor(Color.RED);
TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
summaryView.setTypeface(fontStyle);
summaryView.setTextColor(Color.RED);
}
}
Run Code Online (Sandbox Code Playgroud)
CustomPreferenceCategory:
public class CustomPreferenceCategory extends PreferenceCategory {
Typeface fontStyle;
public CustomPreferenceCategory(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public CustomPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomPreferenceCategory(Context context) {
super(context);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
fontStyle = Typeface.createFromAsset(CA.getApplication()
.getApplicationContext().getAssets(), AppConstants.fontStyle);
TextView titleView = (TextView) view.findViewById(android.R.id.title);
titleView.setTypeface(fontStyle);
// titleView.setTextColor(Color.RED);
}
}
Run Code Online (Sandbox Code Playgroud)
在您Preference.xml需要创建PreferenceCategory和Preference使用这些自定义类.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CustomPreferenceCategory android:title="@string/manage_device_title"
android:key="@string/device_category">
<CustomPreference android:title="@string/manage_device"
android:key="@string/manage_device_KEY"
android:summary="@string/device_summary" >
</CustomPreference>
</CustomPreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
注意:在根据需要引用preference.xml和fontStyle添加时,请使用CustomPerenceCategory和CustomPreference的正确包名.
| 归档时间: |
|
| 查看次数: |
1246 次 |
| 最近记录: |