gpt4 book ai didi

android - 将 typeFace 设置为 NumberPicker

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:48:36 28 4
gpt4 key购买 nike

如何在 NumberPicker 中更改字体类型。我尝试这样做,但字体没有改变。任何想法?P.S: color 和 textSize 有变化。

public class NumberPicker extends android.widget.NumberPicker {
private Context context;
private Typeface tfs;
public NumberPicker(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
tfs = Typeface.createFromAsset(context.getAssets(),"fonts/font.ttf");
}

@Override
public void addView(View child) {
super.addView(child);
updateView(child);
}

@Override
public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {
super.addView(child, index, params);
updateView(child);
}

@Override
public void addView(View child, android.view.ViewGroup.LayoutParams params) {
super.addView(child, params);
updateView(child);
}

private void updateView(View view) {
if(view instanceof EditText){
((EditText) view).setTypeface(tfs);
((EditText) view).setTextSize(25);
((EditText) view).setTextColor(Color.RED);
}
}

}

字体和路径工作正常。我将它用于我的自定义 TextView 。

最佳答案

在您的 style.xml 中添加以下样式。

<style name="NumberPickerCustomText">
<item name="android:textSize">22sp</item> // add if you want to change size
<item name="android:fontFamily">@font/lato_regular</item> // add font (this font folder is present in res folder)
</style>

以 XML 格式直接将此样式添加到您的号码选择器。

android:theme="@style/NumberPickerCustomText"

关于android - 将 typeFace 设置为 NumberPicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25794611/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com