问题描述
我使用在我的项目。
有关翻译的目的,我与自定义字体自定义的TextView。该WheelView使用的TextView来显示文本。我想用在Wheelview自定义的TextView,使其显示自定义字体的文本。我怎么做?
我不想改变wheelview的原始来源,万一我不得不将其用于其他应用程序。
code中的wheelview适配器:
/ **
*适配器基于字符串的车轮。亮点当前值。
* /
私有类DateArrayAdapter扩展ArrayWheelAdapter<串GT; {
当前项目的//指数
INT CURRENTITEM;
//项目的索引突出
INT CurrentValue的; / **
*构造
* /
公共DateArrayAdapter(上下文的背景下,字符串[]项目,目前INT){
超(背景下,项目);
this.currentValue =电流;
setTextSize(16);
} @覆盖
保护无效configureTextView(TextView的视图){
super.configureTextView(视图);
如果(CURRENTITEM == CurrentValue的){
view.setTextColor(getResources()的getColor(R.color.holo_blue));
}
view.setTypeface(Typeface.SANS_SERIF);
view.setTextSize(18);
} @覆盖
公共景观的getItem(INT索引,视图cachedView,父母的ViewGroup){
CURRENTITEM =指数;
返回super.getItem(索引,cachedView,父母);
}
}
创建您自己的视图的布局XML。让我们说它是 layout_item.xml
。设置你的观点(自定义的TextView)的ID才能使用文本机器人:ID =@ + ID /文
您的适配器上使用这样的:
adapter.setItemResource(R.layout.layout_item);
adapter.setItemTextResource(R.id.text);
我现在想它应该工作
I am using Yuri Kanivets' WheelView in my project.
For translation purposes, I have made a custom TextView with custom Font. The WheelView uses TextView to display text. I would like to use the custom Textview in Wheelview so that it displays the text in custom font. How do I do that?
I don't want to change the original source of wheelview, in case I have to use it for other apps.
Code of the wheelview adapter:
/**
* Adapter for string based wheel. Highlights the current value.
*/
private class DateArrayAdapter extends ArrayWheelAdapter<String> {
// Index of current item
int currentItem;
// Index of item to be highlighted
int currentValue;
/**
* Constructor
*/
public DateArrayAdapter(Context context, String[] items, int current) {
super(context, items);
this.currentValue = current;
setTextSize(16);
}
@Override
protected void configureTextView(TextView view) {
super.configureTextView(view);
if (currentItem == currentValue) {
view.setTextColor(getResources().getColor(R.color.holo_blue));
}
view.setTypeface(Typeface.SANS_SERIF);
view.setTextSize(18);
}
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
currentItem = index;
return super.getItem(index, cachedView, parent);
}
}
Create a layout xml with your own view. Let us say it is layout_item.xml
. Set the id of your view (the custom textview) to text using android:id="@+id/text"
Use this on your adapter:
adapter.setItemResource(R.layout.layout_item);
adapter.setItemTextResource(R.id.text);
I guess now it should work
这篇关于更改WheelView的TextView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!